BK201 Posted June 19, 2012 Share Posted June 19, 2012 I'm just learning AJAX/JS and I'm trying to just make a basic, request. As I've found out you get no error messages when writing in JS so that's not helping. Nothing happens when I load the page. Any help is greatly appreciated, I've looked over several resources but I can't seem to figure out whats wrong. test1.html <script language="javascript" type="text/javascript"> <!-- function createRequestObject() { var http; http = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); return http; } function processResponse() { var response; if (http.readyState == 4) { response = http.responseText; return response; } } function request(a, b) { http.open("GET", "test1.php?figure1=" + a + "&figure2=" + b, true); http.onreadystatechange = processResponse(); http.send(null); } --> </script> createRequestObject(); request(1, 2); document.alert(response); test1.php <?php echo $_GET['figure1'] + $_GET['figure2']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/264456-new-to-ajax-simple-question/ Share on other sites More sharing options...
Jessica Posted June 19, 2012 Share Posted June 19, 2012 Install Firebug on Firefox to get helpful debugging. Quote Link to comment https://forums.phpfreaks.com/topic/264456-new-to-ajax-simple-question/#findComment-1355239 Share on other sites More sharing options...
Mahngiel Posted June 19, 2012 Share Posted June 19, 2012 Install Firebug on Firefox to get helpful debugging. And you can easily check the values of what you are expecting to send + receive with console.log( 'show me the money!' ); Quote Link to comment https://forums.phpfreaks.com/topic/264456-new-to-ajax-simple-question/#findComment-1355293 Share on other sites More sharing options...
freeublue Posted June 20, 2012 Share Posted June 20, 2012 Try learning Jquery to handle your ajax it often replaces 40 lines of code with 4. http://www.jquery.com $.post("filename", {value to get : js value}, function(data){ if (data.length>0){ $("#div name for holding result").html(data); Maybe this solution will assist you. Quote Link to comment https://forums.phpfreaks.com/topic/264456-new-to-ajax-simple-question/#findComment-1355583 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.