Jump to content


Photo

Creating instance of xmlhttprequest object


  • Please log in to reply
2 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 August 2006 - 01:23 PM

if (window.XMLHttpRequest)     // Object of the current windows
{ 
        request = new XMLHttpRequest();     // Firefox, Safari, ...
} 
else 
if (window.ActiveXObject)   // ActiveX version
{
       request = new ActiveXObject("Microsoft.XMLHTTP");    // Internet Explorer 
}
Will those 2 take care of all browsers, or are there a few more I can put in there, to make totally sure that it's going to be cross browser compatible, atleast for the most part.  Should I surround the whole thing, and only do so if javascript is activated.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 August 2006 - 01:55 PM

Take a look at the Yahoo! Connection Manager at http://developer.yah...yui/connection/
It takes care of the differences between the browsers and presents them in a known format to your script.

The package is Javascript.

Ken

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 06 September 2006 - 02:53 PM

Taken from an AJAX Freaks tutorial:
function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users