shank8 Posted April 5, 2012 Share Posted April 5, 2012 I am doing a friend a favor by converting his website that set up for production into development. I have changed all the database information, but I am still have problems running the AJAX. I don't know a whole lot about it so it is probably something simple. An ajax request is sent when a new user tries to register. The request is sent to this javascript file var returnValue;function ajaxRequest(url, parameters){ ajax(url, parameters); return returnValue;}function ajax(url, parameters){ if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.open("POST", url, false);//Send the proper header information along with the requestxmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");xmlhttp.setRequestHeader("Content-length", parameters.length);xmlhttp.setRequestHeader("Connection", "close");xmlhttp.onreadystatechange = function() {//Call a function when the state changes. if( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) { returnValue = xmlhttp.responseText; } }xmlhttp.send(parameters);} None of this code is mine, so don't ask why they use 2 functions to do one thing.. However, the ajaxRequest() function is not returning anything when it should be returning a value. Is there something I need to fix so that it works on my local XAMPP server? I am using Google Chrome. Any help is great. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 5, 2012 Share Posted April 5, 2012 It might mean that the request is failing, the global returnValue variable only gets set if the request succeeded. Check the developer tools in Chrome to look for Javascript errors in the console, and check the Network tab to look for the request going out so you can verify if it succeeds and returns a 200 status. Link to comment Share on other sites More sharing options...
shank8 Posted April 5, 2012 Author Share Posted April 5, 2012 thanks I will give it a try Link to comment Share on other sites More sharing options...
shank8 Posted April 5, 2012 Author Share Posted April 5, 2012 Ok so i think that worked. I get the error: register.php in Name/Path Method: POST Status 404 NOT FOUND Type: text/html ect.. So the status is not found. What does that mean? EDIT: So i fixed a url problem that was there before..idk how it worked in production with that error. So now the network tool shows everything is included right, however, the AJAX still does not return a value. It just returns undefined Link to comment Share on other sites More sharing options...
justsomeguy Posted April 5, 2012 Share Posted April 5, 2012 If you're looking at the network tab you should be able to see the ajax request to the PHP file, you can check that request to see what the status was (it needs to be 200 for your code to work), and you can also check the response from PHP. You can also check the response headers, the content type needs to be text or HTML for the responseText property to have the response from the server. If it's undefined then either the request isn't succeeding or the content type is wrong. Link to comment Share on other sites More sharing options...
shank8 Posted April 5, 2012 Author Share Posted April 5, 2012 ok thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.