mgs019 Posted March 30, 2007 Share Posted March 30, 2007 Hi, This is driving me slightly round teh twist. I want to use an AJAX XMLhttprequest thingy to dynamically display diamond information in a webpage as the attributes change in hidden form elements controled by javascript sliders. I am using an iframe at teh moment but it clicks like mad and is irritating so this seems far better. However, I coied the code from the w3schools website and made a couple of very minor changes (the url) but it does not work!!! The js file is associated because firefox web developer tools lists it correctly. The relevent HTML code is: <div id="diadetails">Diamond details</div><input type="button" name="update" value="update" onmouseover="showUser()" /> Obviously the button is just to trigger it. The script is: var xmlHttpfunction showUser() { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="/includes/guideprice.php" url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("diadetails").innerHTML=xmlHttp.responseText } }function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } All that happens is that in internet explorer it says error on page at line ... char 1 object expected. It gives an error for every triggering. I just cannot figure out what object it wants. Any idea guys this is really driving me insane ??? :'( Thanks alot. Martin Quote Link to comment Share on other sites More sharing options...
lszanto Posted March 31, 2007 Share Posted March 31, 2007 Are you trying to send a value cause your not sending anything at the moment. Quote Link to comment Share on other sites More sharing options...
mgs019 Posted March 31, 2007 Author Share Posted March 31, 2007 I was. But at the moment I am just trying to get anything to display. I had e.g. var col = document.forms.colour.value For several variables in the script which then add to the url. It works well in an iframe by changing the url using these variables. However it did not work so I thought if I simplified it a bit it would be easier to work out where it is going wrong. Then I can add details later. Martin Quote Link to comment Share on other sites More sharing options...
mainewoods Posted April 2, 2007 Share Posted April 2, 2007 line 1 should have a semicolon before 'function': var xmlHttpfunction showUser() --you should always terminate your js statements with a semicolon Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 2, 2007 Share Posted April 2, 2007 change var xmlHttpfunction showUser() to var xmlHttpfunction; function showUser() mainewoods = AJAX King Quote Link to comment Share on other sites More sharing options...
mgs019 Posted April 2, 2007 Author Share Posted April 2, 2007 Cheers, That worked great. I thought it would be something simple like that but I am a noob when it comes to ajax. Cheers again, Martin Quote Link to comment Share on other sites More sharing options...
mainewoods Posted April 2, 2007 Share Posted April 2, 2007 Thanks for that comment MadTechie! 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.