| | |
Ajax script not working w/ IE7+
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Greetings. I'm stumped with a particular problem involving an ajax script that works for Firefox, Opera, Safari, and Chrome... but unfortunately does not work with any version of IE (*actually I haven't tested IE6 or less yet, but who cares about those anymore*).
On the HTML side, a list of hospitals is generated, and when a hospital is selected, the content changes, based on the selection. In addition, the script also runs 'onload' to generate the initial list. The script is below, and the incomplete example can be seen at http://www.aahcp.com/nusurvey.php
Thanks in advance for any assistance!
On the HTML side, a list of hospitals is generated, and when a hospital is selected, the content changes, based on the selection. In addition, the script also runs 'onload' to generate the initial list. The script is below, and the incomplete example can be seen at http://www.aahcp.com/nusurvey.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function narrowSelection(){ xmlhttp=GetXmlHttpObject(); if (xmlhttp==null){alert("Browser does not support HTTP Request");return;} var url="scripts/multiscript.php?narrowSelection="+document.getElementById('keyword').value; xmlhttp.onreadystatechange=stateChangedA; xmlhttp.open("GET",url,true); xmlhttp.send(null);} function stateChangedA(){ if (xmlhttp.readyState==4){document.getElementById("hospitallist").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;}
Hi kintaro,
try this code:
try this code:
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> // <![CDATA[ var d = document; var GetXmlHttpObject = 0; if ( d.getElementById ) { ( GetXmlHttpObject = function( ) { var req = 0; if ( req = new XMLHttpRequest() ) { return req; } try { var client = [ "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ]; var cLen = client.length; for( var x = 0; x < cLen; x++ ) { if( req = new ActiveXObject( client[ x ] )) { return req; } } } catch( e ) { alert( "Browser does not support HTTP Request." ); return 0; } } ); var stateChangedA = function() { d.getElementById("hospitallist").innerHTML = ( function( xhr ) { if(( { 4 : 4, complete : 4 }[ xhr.readyState ] )) return xhr.responseText; else return "HTTP Request failed!"; } )( this ); } var narrowSelection = function() { var xmlHttp = GetXmlHttpObject(); if ( xmlHttp ) { var url = "./script/multiscript.php?narrowSelection=" + d.getElementById("keyword").value; (( "overrideMimeType" in xmlHttp ) ? xmlHttp.overrideMimeType("text/xml") : xmlHttp ); xmlHttp.onreadystatechange = stateChangedA; xmlHttp.open( "GET", encodeURIComponent( url ), true ); xmlHttp.send( null ); return; } void( 0 ); }; window.onload = narrowSelection; } // ]]> </script>
Last edited by essential; Aug 23rd, 2009 at 1:51 pm.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Hi,
this should be able to work under rough condition:
this should be able to work under rough condition:
javascript Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>www.daniweb.com</title> <script type="text/javascript"> // <![CDATA[ var GetXmlHttpObject = function() { var xml = 0; try { if ( "XMLHttpRequest" in window ) { xml = new XMLHttpRequest(); } else if ( "ActiveXObject" in window ) { var client = [ "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ]; try { for ( var x = 0; x < client.length; x++ ) { if ( new ActiveXObject( client[ x ] )) { xml = new ActiveXObject( client[ x ] ); break; } } } catch( e1 ) { xml = 0; } } } catch( e ) { if ( "createRequest" in window ) { xml = window.createRequest(); } } return xml; }; var narrowSelection = function() { var xmlHttp = GetXmlHttpObject(); if ( xmlHttp ) { var keywords = document.getElementById( "keyword" ) || keyword; var url = "script/multiscript.php?narrowSelection=" + encodeURIComponent( keywords.value ); (( "overrideMimeType" in xmlHttp ) ? xmlHttp.overrideMimeType("text/xml") : xmlHttp ); xmlHttp.onreadystatechange = function() { var hospital = document.getElementById( "hospitallist" ) || hospitallist; if ( { 4 : 4, complete : 4 }[ this.readyState ] && ( { 0 : "offline", 200 : "online" }[ this.status ] )) { hospital.innerHTML = this.responseText; } }; xmlHttp.open( "GET", url, true ); xmlHttp.send( null ); return; } alert( "Your Browser does not support HTTP Request!" ); }; // ]]> </script> </head> <body> <noscript> <p>This site requires a browser that support <b>JavaScript</b>. </p> </noscript> <div> <div style="margin-bottom : 1em;" id="hospitallist"></div> Enter Keyword: <input type="text" id="keyword" name="keyword" value="" size="30" onchange="narrowSelection()" /> </div> </body> </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
![]() |
Similar Threads
- minimal AJAX script works in Firefox, but not in IE, Opera, or Chrome (JavaScript / DHTML / AJAX)
- AJAX snippet not working with Firefox (JavaScript / DHTML / AJAX)
- ajax/mysql not working... pls help :) (JavaScript / DHTML / AJAX)
- AJAX Stopped Working (JavaScript / DHTML / AJAX)
- Javascript not working in IE7 but running in IE5...cross browser problem plz help (JavaScript / DHTML / AJAX)
- Ajax script not working on firefox (JavaScript / DHTML / AJAX)
- body onLoad not working in IE7 (JavaScript / DHTML / AJAX)
- Script is not working in linux (Shell Scripting)
- simple ajax script problem (JavaScript / DHTML / AJAX)
- Script To Uninstall IE7 (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: I got this code for email validation . I know its simple i a newbie , explanation ?
- Next Thread: Need a DIV always at bootm by my way!
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





