Jump to content

Confused About Xmlhttprequest


therschbach
 Share

Recommended Posts

I want the content of file test.html...

function ajaxFunction(){var xmlHttp;try{  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();}catch (e)  {  // Internet Explorer  try    {        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }catch (e) {      try    {          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");          }  catch (e)    {          alert("Your browser does not support AJAX!");    return false;          }     }  }  xmlHttp.onreadystatechange=function()    {    if(xmlHttp.readyState==4)      {      document.getElementById("main").innerHTML = xmlHttp.responseText;      }    }  xmlHttp.open("GET","test.html",true);  xmlHttp.send(null);  }

However, when the page loads, the DIV doesn't get filled with anything, nor am I seeing any js errors. Any ideas what I'm doing wrong? Thanks again for your help.

Link to comment
Share on other sites

You've commented out the object assignment:// Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest();I swear someone else had the same thing the other day. This part needs to be on its own line:xmlHttp=new XMLHttpRequest();

Link to comment
Share on other sites

All right, I tried your code, and it worked. But I had to move 1-2 try statements so they were uncommented. The formatting could be messed up on both ends.I hope the HTML file you're connecting to isn't a complete HTML document?

Link to comment
Share on other sites

All right, I tried your code, and it worked. But I had to move 1-2 try statements so they were uncommented. The formatting could be messed up on both ends.I hope the HTML file you're connecting to isn't a complete HTML document?
test.html only contains "Test 1 2 3"... no html or anything else. Just plain text. Would it be useful for me to post the html code for my index2.html?
Link to comment
Share on other sites

Would it be useful for me to post the html code for my index2.html?
Not really.Are you still having problems? Have you run any diagnostics? Using the alert function to print out variables from time to time can be very useful. Like, you could put an alert at the start of your readystate function just to let you know the function got called. You could alert(xmlHttp.responseText) just to make sure it's arriving. Before all that, you could alert(xmlHttp) just to make sure you're getting an object.If none of that helps, maybe it's time to post everything.
Link to comment
Share on other sites

I apologize, I haven't had time to try anything for the past few days. I just reloaded the index2.html, the js script which it points to, and the test.html and it still doesn't work. I tested to make sure the script is actually getting called, and it is. I typed some text into the container div to make sure it would show up and it did.I'll do as you recommended with the plugin for FF when I get a chance.

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...