therschbach Posted March 1, 2009 Share Posted March 1, 2009 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 More sharing options...
jeffman Posted March 1, 2009 Share Posted March 1, 2009 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 More sharing options...
therschbach Posted March 1, 2009 Author Share Posted March 1, 2009 This may have been caused by copying & pasting from notepad++ to the board. I'll try it again and make sure this isn't the problem. Link to comment Share on other sites More sharing options...
therschbach Posted March 3, 2009 Author Share Posted March 3, 2009 Ok, I edited it and it doesn't work. I think the formatting got messed up when I pasted it onto the forum. Any other ideas? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 3, 2009 Share Posted March 3, 2009 Get Firebug installed for Firefox and use that to test. In addition to showing error messages, you can also use it to look at the XHR requests going out and coming back. Link to comment Share on other sites More sharing options...
jeffman Posted March 3, 2009 Share Posted March 3, 2009 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 More sharing options...
therschbach Posted March 4, 2009 Author Share Posted March 4, 2009 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 More sharing options...
jeffman Posted March 4, 2009 Share Posted March 4, 2009 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 More sharing options...
therschbach Posted March 6, 2009 Author Share Posted March 6, 2009 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 More sharing options...
therschbach Posted March 7, 2009 Author Share Posted March 7, 2009 Ahhaaaa!! It works! I remembered that the 2nd time I tried it after checking to make sure the proper things were commented out, I forgot to put something to call the script. I added my window.onload back in and it works!! Thanks a bunch! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.