Total members 11889 |It is currently Thu Mar 28, 2024 10:14 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Dispatching an XMLHttpRequest
I'll start at the beginning of the Ajax sequence: creating and dispatching an XMLHttpRequest from the browser. Unfortunately, the method to create an XMLHttpRequest differs from browser to browser. The JavaScript function in Listing 2 smoothes out these browser-dependent wrinkles, detecting the correct approach for the current browser and returning an XMLHttpRequest ready to use. It's best to think of this as boilerplate code: simply copy it into your JavaScript library and use it when you need an XMLHttpRequest.

Code:
/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function newXMLHttpRequest() {

  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {

      // Failed to create required ActiveXObject

      try {
        // Try version supported by older versions
        // of Internet Explorer

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }

  return xmlreq;
}
 





Author:
Newbie
User avatar Posts: 23
Have thanks: 1 time
Post new topic Reply to topic  [ 1 post ] 




Topic Tags

AJAX Request
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com