Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax app works in some browers, not others

My ajax app works fine in Firefox, but not in IE8. Specifically, the ajax functionality doesn't work.

Here's the code I'm using:

function createXMLHttpRequest()
{
  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;
}

This is the error:

Object doesn't support this property or method
ajax.js
Code:0
Line : 6
Char : 5

It works perfect in Firefox.

What is the problem with my code ?

like image 708
Satish Ravipati Avatar asked Sep 26 '09 21:09

Satish Ravipati


1 Answers

straight out of jQuery:

return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :
                              new XMLHttpRequest();
like image 53
Dan Beam Avatar answered Oct 15 '22 10:10

Dan Beam