Jump to content

getting no response from Ajax call


peasepud

Recommended Posts

evening folks,

 

I have 6 seperate Ajax calls within a page, 5 are working fine but the latest just never responds. my code is:

function amend_book(bookid) {
   alert(bookid); 
   var xmlhttp = new XMLHttpRequest();
   xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var result = xmlhttp.responseText;
            
            var resbits = result.split("|");
            document.getElementById("seltog").value = resbits[0];
            document.getElementById("bookdate").value = resbits[1];

            document.getElementById("booktime").value = resbits[2];
        }
    var newurl = "get_booking.php?bookid=" + bookid;
    xmlhttp.open("GET", newurl , true);
    xmlhttp.send();
    }
}

Im running firebug and theres no errors appearing, I put the alert in at line 2 and it correctly outputs the bookid when the call is made so I know its being called. I've also tried alerting the newurl where it is but nothing appears when i do that, if I move the var newurl to the 2nd line and then alert it correctly shows the URL. Copying and pasting that into a browser gives me the expected results so I know the url is fine and the php works as expected.

 

No matter what I do though, I cant seem to confirm that the xmlhttp.open is ever actually taking place.

 

Like I say theres another 5 of these in the page and all are exact apart from the GET Url and what I do with the results.

 

Anyone have any ideas or alternatively any thoughts on how I debug it better?

Edited by peasepud
Link to comment
Share on other sites

  • 2 months later...

you can't seem to confirm xmlhttp.open is taking place because it is not taking place

 

the three lines from newurl to xmlhttp.send is inside xmlhttp.onreadystatechange function so never gets triggered.

function amend_book(bookid) {
   alert(bookid); 
   var xmlhttp = new XMLHttpRequest();
   xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var result = xmlhttp.responseText;
            
            var resbits = result.split("|");
            document.getElementById("seltog").value = resbits[0];
            document.getElementById("bookdate").value = resbits[1];

            document.getElementById("booktime").value = resbits[2];
        }
    }//add here
    var newurl = "get_booking.php?bookid=" + bookid;
    xmlhttp.open("GET", newurl , true);
    xmlhttp.send();
   // } remove this line
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.