lam0rak Posted November 3, 2006 Share Posted November 3, 2006 Evening all!It's my first attempt at AJAX and normally I find w3Schools examples really good but I cannot for the life of me seem to get any of their AJAX examples working. I don't know asp so I wrote a server script file in php which it says on the site is possible but when I run the whole thing in IE it say's unspecified error on line 24. In firefox it says nothing it simply just doesn't work. I'm fairly sure my php is sound can anyone check my javascript who is more wise in these things?! I'll post the whole thing here anyway!INDEX.HTM <html><head><script src="./js/selectcustomer.js"></script></head><body><form>Select a Customer:<select name="customers" onchange="showCustomer(this.value)"><option value="24">Preferences<option value="25">SERIOUS TECH...<option value="26">Dubious Poll</select></form><p><div id="txtHint"><b>Posts will load here...</b></div></p></body></html> SELECTCUSTOMER.JS var xmlHttpfunction GetXmlHttpObject(){ var objXMLHttp=nullif (window.XMLHttpRequest){objXMLHttp=new XMLHttpRequest()}else if (window.ActiveXObject){objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}return objXMLHttp}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText} } function showCustomer(str){ xmlHttp=GetXmlHttpObject()if (xmlHttp==null){alert ("Browser does not support HTTP Request")return} var url="../scripts/getcustomer.php"url=url+"?q="+strurl=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true)xmlHttp.send(null)} GETCUSTOMER.PHP <?phpinclude "../includes/connect.inc";$q=$_GET["q"]; $sql = mysql_query("SELECT * FROM bucs_customers WHERE updateID='$q'"); $response = mysql_fetch_assoc($sql); echo "----------------------------- \n"; echo "AJAX Test Call\n"; echo "----------------------------- \n \n"; echo $response['customer']." (".$response['datejoined'].") \n"; echo $response['email'];?> I'm really greatful for any and all help on this guys my javascript knolwedge is pretty minimal so if I am missing something I cant spot what it is! please help!!Rich Link to comment Share on other sites More sharing options...
jesh Posted November 3, 2006 Share Posted November 3, 2006 So, what happens when you visit the following, do any of them work?../scripts/getcustomer.php?q=24../scripts/getcustomer.php?q=25../scripts/getcustomer.php?q=26Do you have any idea what line IE says line 24 is? Link to comment Share on other sites More sharing options...
lam0rak Posted November 3, 2006 Author Share Posted November 3, 2006 So, what happens when you visit the following, do any of them work?../scripts/getcustomer.php?q=24../scripts/getcustomer.php?q=25../scripts/getcustomer.php?q=26Do you have any idea what line IE says line 24 is? http://www.insecureinc.com/AJAX/scripts/getcustomer.php?q=24http://www.insecureinc.com/AJAX/scripts/getcustomer.php?q=25http://www.insecureinc.com/AJAX/scripts/getcustomer.php?q=26Thats a direct link to the php script at the moment its accessing an old table I used to store news about an even older site. I just picked the id's as 24, 25, 26 in the select box because they correspond to different data in that table. If you click the link you'll see the php side works fine. I think line 24 might be in the JS file in this function:function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") < line 24?{ document.getElementById("txtHint").innerHTML=xmlHttp.responseText} } Link to comment Share on other sites More sharing options...
jesh Posted November 3, 2006 Share Posted November 3, 2006 Hmm, I have two suggestions. For your handler (stateChanged()), try this instead: function stateChanged(){ if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } }} Then, in your showCustomer() function, change: xmlHttp.send(null) to xmlHttp.send(""); Link to comment Share on other sites More sharing options...
lam0rak Posted November 4, 2006 Author Share Posted November 4, 2006 Thanks so much mate!! I tried this and fiddled around with it a bit more and have managed to get it working! you're a legend! cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now