AL156 Posted December 3, 2009 Share Posted December 3, 2009 I took these Two examples (from the php/ajax part of w3schoolsand) and integrated them into my site: http://nuke.empireindustry.com/Blogspiracy/They both work as they should, but they display in the same space overwriting each other.This must be a simple problem but I just can't figure it out.Thanks in advance,AL156 THE CD EXAMPLE:var xmlhttp;function showCD(str) // solve the problem of creating different XMLHTTP objects for different browsers.{xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; }var url="processReq/getcd.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);} function stateChanged() {if (xmlhttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}}function GetXmlHttpObject(){if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); }if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); }return null;}THE GET USER EXAMPLE:var xmlhttp;function showUser(str){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }var url="processReq/getuser.php";url=url+"?r="+str;//?q=url=url+"&sid="+Math.random();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function stateChanged(){if (xmlhttp.readyState==4){document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;}}function GetXmlHttpObject(){if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); }if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); }return null;} Link to comment Share on other sites More sharing options...
thescientist Posted December 3, 2009 Share Posted December 3, 2009 sorry, which parts are overwriting each other? Link to comment Share on other sites More sharing options...
jeffman Posted December 3, 2009 Share Posted December 3, 2009 Your two files each have a function by the name, stateChanged(). That won't work. The second to load clobbers the first, so that ALL your AJAX data gets passed to the second one. The quick and dirty solution is just to give your stateChanged functions separate names.Eventually, you'll want to combine some of this stuff so you're not duplicating code. Link to comment Share on other sites More sharing options...
AL156 Posted December 3, 2009 Author Share Posted December 3, 2009 sorry, which parts are overwriting each other?The CD script is overwritting the User script. Link to comment Share on other sites More sharing options...
AL156 Posted December 3, 2009 Author Share Posted December 3, 2009 The CD script is overwritting the User script.I tried giving the functions unique names:stateChangeda()stateChanged()but this did not work for me, just adding the 'a' should have done it, right? Link to comment Share on other sites More sharing options...
AL156 Posted December 3, 2009 Author Share Posted December 3, 2009 I tried giving the functions unique names:stateChangeda()stateChanged()but this did not work for me, just adding the 'a' should have done it, right?I forgot to add that when I changed the function name the overwritting moves from the User display area to the CD display area.AL156 Link to comment Share on other sites More sharing options...
jeffman Posted December 3, 2009 Share Posted December 3, 2009 You got it halfway. Function names are different; now the callback assignments did to match. You have this:xmlhttp.onreadystatechange=stateChanged;...function stateChangeda()See the problem? Link to comment Share on other sites More sharing options...
AL156 Posted December 3, 2009 Author Share Posted December 3, 2009 You got it halfway. Function names are different; now the callback assignments did to match. You have this:xmlhttp.onreadystatechange=stateChanged;...function stateChangeda()See the problem?I do, I did, It works!I would feel better if the problem were a semicolon, what the heck.Thank you very much, that's been on the back burner for a few weeks.AL156 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.