By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

AJAX problem on IE7

P: 16
Hello,

I'm having problem implementing AJAX on IE7. In other browser it works totally fine. In IE7, if i enable the Enable Native XMLHTTP support, everything just went wrong.

Here is the XMLHTTP request code : (thanks to www.masykur.web.id)

----------------
Expand|Select|Wrap|Line Numbers
  1.  http_request = false ;
  2.         if (window.XMLHttpRequest) { 
  3.             http_request = new XMLHttpRequest();
  4.             if (http_request.overrideMimeType) {
  5.                 http_request.overrideMimeType('text/xml');
  6.  
  7.             }
  8.         } else if (window.ActiveXObject) { // IE
  9.             var aVersions = [ "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "Microsoft.XMLHTTP" ];
  10.             for (var i = 0; i < aVersions.length; i++) {
  11.                 try { http_request = new ActiveXObject(aVersions[i]);
  12.                     break;
  13.                 }
  14.                 catch (e)
  15.                 {
  16.                 // Do nothing 
  17.                 } 
  18.             }
  19.         }
------------

But if i disable the Enable Native XMLHTTP support, it just run smoothly.
I've read from several forums that this problem is quite common, but i just can't find out the work-around.


How do i overcome this problem?
Since out there i can't tell the IE7 user to 'disable their XMLHTTP native'.
Btw, i guess in IE6 there's no problem at all.

Thanks...
Oct 21 '08 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
some ways I would try to solve this:
- try-catch on both objects
- try the ActiveXObject first

this one is working fine for me:
Expand|Select|Wrap|Line Numbers
  1.     try {
  2.         request = new XMLHttpRequest();
  3.     }
  4.     catch (e){
  5.         try {
  6.             request = new ActiveXObject("Msxml2.XMLHTTP"); // IE 5
  7.         } catch (e) {
  8.             try {
  9.                 request = new ActiveXObject("Microsoft.XMLHTTP"); // IE 6
  10.             } catch (e) {
  11.                 alert("...your error message here...");
  12.                 return false;
  13.             }
  14.         }
  15.     }
must proceed, will check later

regards
Oct 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.