Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    xmlhttprequest POST to php file wont work

    My Code:

    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:

    Code:
    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?

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    since the simple echo is working this is not a problem with the XMLHttpRequest...most likely there some problem with your php script...
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    http.onreadystatechange = function() {
        while(http.readyState == 1) {
            wait until upload.php processing finished ...
        }
    }
    Last edited by edzillion; 11-21-2008 at 04:18 PM. Reason: clarity

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by edzillion View Post
    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?)
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •