• Post Reply Bookmark Topic Watch Topic
  • New Topic

Xmlhttprequest post error

 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a javascript function for a POST request from XMLHttprequest object:
function lookup(field) {
....
if (window.XMLHttpRequest) { req = new XMLHttpRequest(); }
else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); }
var formdata = "ajaxreq=true";
req.Open("POST","directoryBrowser.jsp");
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.onreadystatechange = processXMLResponse;
req.send(formdata);
}

This request is generated from within the directoryBrowser.jsp itself(on the keyup event of the searchField custom component).
This post-back is not successful as it is not causing the decode method of the component to be executed.

What is wrong?Does the POST url need to contain 'faces' in the URI too?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one thing is are you sure this code actually runs

this is wrong req.Open("

this is right req.open("

case matters...

Eric
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the the request to
"req.onreadystatechange = processXMLResponse;\n" +
"var formdata = \"ajaxreq=true\";\n" +
"req.open(\"POST\",\"directoryBrowser.jsp\");\n" +
"req.setRequestHeader(\"Content-length\", formdata.length);\n" +
"req.setRequestHeader(\"Content-Type\",\"application/x-www-form-urlencoded\");\n" +
"req.setRequestHeader(\"Connection\", \"close\");\n" +



"req.send(formdata);}\n"

And when i print out the req.responsetext i see the html of the directoryBrowser.jsp being printed out - but the decode is still not called.
If i submit the form explicitly - I see the decode being executed ;so the POST request is till not being recognized.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!