mb81 Posted May 17, 2006 Share Posted May 17, 2006 I am working on a simple AJAX function, but I seem to be having trouble with the http.open in the following code and I'm not sure what's going wrong. It may be something as simple as a bad a file reference, but I have used both relative and absolute links and neither has worked. I have verified that the http is an object. Any help would be appreciated.variablepassed:file: ./ajaxtoolbox/checkusername.phpargs: ?username=testsendtodivID= 'usernamechecktext'turnoffdivID = ''[code]function createRequestObject() { var ro; if (window.XMLHttpRequest) { ro = new XMLHttpRequest(); } else if (window.ActiveXObject) { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.ActiveXObject) { ro = new ActiveXObject("Msxml2.XMLHTTP"); } else { ro = false; } return ro;}var http = createRequestObject();function specifyReq(file,args,sendtodivID,turnoffdivID) { if (http) { http.open('GET',file+args); } http.onreadystatechange = function() { if (http.readyState==4) { document.getElementById(sendtodivID).innerHTML = http.responseText; if (document.getElementById(turnoffdivID)) { document.getElementById(turnoffdivID).innerHTML = ""; } } };}[/code] Quote Link to comment Share on other sites More sharing options...
GBS Posted May 18, 2006 Share Posted May 18, 2006 Hi there,,you forget to use the send method, >http.send(args);<That one should work,,[code]<html><head><title>Testing,,</title></head><body><script>var file="checkusername.php";var args="?username=test";var sendtodivID="usernamechecktext";var turnoffdivID="";function createRequestObject() { var ro; if (window.XMLHttpRequest) { ro = new XMLHttpRequest(); } else if (window.ActiveXObject) { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.ActiveXObject) { ro = new ActiveXObject("Msxml2.XMLHTTP"); } else { ro = false; } return ro;}var http = createRequestObject();function specifyReq(file,args,sendtodivID,turnoffdivID) { if (http) { http.open('GET',file+args); } else { return false; } http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http.send(args); http.onreadystatechange = function() { if (http.readyState==4) { var res = http.responseText;//to debug:alert(res) document.getElementById(sendtodivID).innerHTML = res; if (document.getElementById(turnoffdivID)) { document.getElementById(turnoffdivID).innerHTML = "done"; } } }}</script><div id='usernamechecktext'>testing,,</div><div id='turnoff'>need to log,,...</div><input type="button" value="click" onclick="specifyReq(file,args,sendtodivID,'turnoff')"></body></html></body></html>[/code]I'm not sure about the get method+Ajax (I use $_Post), but I guess the get method needs also to use the 'send' method,,Hoping it helps,,l8tr,, Quote Link to comment 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.