Jump to content

Display Trouble


AL156
 Share

Recommended Posts

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;}

Edited by AL156
Link to comment
Share on other sites

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.

Edited by Deirdre's Dad
Link to comment
Share on other sites

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

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?

Edited by Deirdre's Dad
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...