peasepud Posted October 30, 2015 Share Posted October 30, 2015 (edited) 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 October 30, 2015 by peasepud Quote Link to comment https://forums.phpfreaks.com/topic/298920-getting-no-response-from-ajax-call/ Share on other sites More sharing options...
maxxd Posted October 30, 2015 Share Posted October 30, 2015 What does the response say in FireBug? Could be an error in the get_booking script - the response should let you know. Quote Link to comment https://forums.phpfreaks.com/topic/298920-getting-no-response-from-ajax-call/#findComment-1524809 Share on other sites More sharing options...
kaleshwarchand Posted January 9, 2016 Share Posted January 9, 2016 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 } Quote Link to comment https://forums.phpfreaks.com/topic/298920-getting-no-response-from-ajax-call/#findComment-1529337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.