...

View Full Version : xmlhttprequest POST to php file wont work



edzillion
11-21-2008, 03:55 PM
My Code:


http=new XMLHttpRequest();
var url = "upload.php";
params = getParams();
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);

I am sending a lot of parameters - but that doesn't seem to cause the problem. The upload.php file runs fine if there is very little processing in it. If I just put in an echo, I get the response in an alertbox fine:


alert(http.responseText);

But the php file really needs to loop through the parameters and upload them to a mysql table. And if I uncomment this loop (even though there is only one iteration) then I get no response and the php file doesn't seem to execute at all.

Any ideas?

shyam
11-21-2008, 04:04 PM
since the simple echo is working this is not a problem with the XMLHttpRequest...most likely there some problem with your php script...

edzillion
11-21-2008, 04:17 PM
Ok, but is there a maximum time a php script invoked by a xmlhttprequest can run for?

If the readystateintegers are:
0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete

Then should I have something like:


http.onreadystatechange = function() {
while(http.readyState == 1) {
wait until upload.php processing finished ...
}
}

shyam
11-21-2008, 05:14 PM
Ok, but is there a maximum time a php script invoked by a xmlhttprequest can run for?
how long does the php script take to execute if invoked from a normal form post? (does it work at all?)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum