| | |
AJAX won't work with IE, but works with Firefox and Safari
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I don't know what happened to my previous topic about this.
But I am using an AJAX menu on a page I am making for somebody, and I used the exact same code w3schools recommends to use:
It works flawlessly in Firefox, Safari, etc., (any browser that adheres to standards), but Internet Explorer doesn't load it, and it gives an error. And in fact, it says the error is on line 169, but the page isn't that many lines long, so I can't find where it is. I'm sure it's on statechanged or one of the xmlHttp=new ActiveXObject lines.
But this is the code w3schools says to use, so I don't know why it's not working.
Any ideas?
Thanks
But I am using an AJAX menu on a page I am making for somebody, and I used the exact same code w3schools recommends to use:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function updatemenu(leagueno, confno, location, mode) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="updatemenu.php"; url=url+"?mode="+mode+"&leagueno="+leagueno+"&confno="+confno+"&loc="+location; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("results").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; }
It works flawlessly in Firefox, Safari, etc., (any browser that adheres to standards), but Internet Explorer doesn't load it, and it gives an error. And in fact, it says the error is on line 169, but the page isn't that many lines long, so I can't find where it is. I'm sure it's on statechanged or one of the xmlHttp=new ActiveXObject lines.
But this is the code w3schools says to use, so I don't know why it's not working.
Any ideas?
Thanks
•
•
Join Date: Aug 2008
Posts: 380
Reputation:
Solved Threads: 33
Sorry, it works in my IE7 and I don't have any of the legacy IE versions around to test it on.
This is what I have from your code above, after some mild reformatting clean up (to my tastes) :-)
w3c_ajax.php
But I didn't really change anything except make xmlHttp local to the function and then use the this keyword in the stateChanged method -- give it a try and see if it works in yours now? If not, what IE version are you using?
...
This is what I have from your code above, after some mild reformatting clean up (to my tastes) :-)
w3c_ajax.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?php if ( $_REQUEST ) { print 'test response'; exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function updatemenu( leagueno, confno, location, mode ) { var xmlHttp = GetXmlHttpObject(); if ( xmlHttp == null ) { alert ( "Your browser does not support AJAX!" ); return; } var url="w3c_ajax.php"; url = url + "?mode=" + mode + "&leagueno=" + leagueno + "&confno=" + confno + "&loc=" + location; xmlHttp.onreadystatechange = stateChanged; xmlHttp.open( "GET", url, true ); xmlHttp.send( null ); } function stateChanged () { if ( this.readyState == 4 ) { if ( this.status == 200 ) { alert( this.responseText ); document.getElementById("results").innerHTML = this.responseText; } else { alert( 'The server failed to process your request' ); } } } 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; } </script> </head> <body> <div id="results"></div> <a href="javascript:" onclick="updatemenu()">Update Menu Test</a> </body> </html>
But I didn't really change anything except make xmlHttp local to the function and then use the this keyword in the stateChanged method -- give it a try and see if it works in yours now? If not, what IE version are you using?
...
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
IE 5.2 for Mac. I don't have a Windows installation in the house. So I have to use it for Mac, which may be kind of old.
But your example displayed 'text response', so I take it that means it worked, right?
I'll have to view it on his laptop then and see if it works, but I have before, and it always said "Error on such and such line" but it was always a much higher number than the actual number of lines in the php file. And I haven't changed anything since the original copy and paste from w3c's site. But I'll have to check it again.
Thanks for your reply.
But your example displayed 'text response', so I take it that means it worked, right?
I'll have to view it on his laptop then and see if it works, but I have before, and it always said "Error on such and such line" but it was always a much higher number than the actual number of lines in the php file. And I haven't changed anything since the original copy and paste from w3c's site. But I'll have to check it again.
Thanks for your reply.
•
•
Join Date: Aug 2008
Posts: 380
Reputation:
Solved Threads: 33
•
•
•
•
IE 5.2 for Mac. I don't have a Windows installation in the house. So I have to use it for Mac, which may be kind of old.
Cheers
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Similar Threads
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- Http request error when using AJAX. (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Replace Chars in String Problem
- Next Thread: How can i go about this?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser captchaformproblem checkbox close codes css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position problem programming prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n





