Home arrow JavaScript arrow Page 4 - Detect Browser Compatibility with the Request Object
JAVASCRIPT

Detect Browser Compatibility with the Request Object


If you use AJAX to improve your visitors' experience when they browse your web site, you may want to try out the hack described in this article. It helps with browser compatibility considerations. This article is excerpted from chapter one of the book Ajax Hacks, written by Bruce W. Perry (O'Reilly; ISBN: 0596101694). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
July 17, 2008
TABLE OF CONTENTS:
  1. · Detect Browser Compatibility with the Request Object
  2. · Using a Function for Checking Compatibility
  3. · Ajax Basics
  4. · Ajax Basics continued

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Detect Browser Compatibility with the Request Object - Ajax Basics continued
(Page 4 of 4 )

Here’s an example of an entire compatibility check:

  /* Wrapper function for constructing a request object.
  
Parameters:
    reqType: The HTTP request type, such as GET or POST.
    url: The URL of the server program.
    asynch: Whether to send the request asynchronously or not. */

  function httpRequest(reqType,url,asynch){
      //Mozilla-based browsers
      if(window.XMLHttpRequest){
         
request = new XMLHttpRequest();
     
} else if (window.ActiveXObject){
          request=new ActiveXObject("Msxml2.XMLHTTP");
          if (! request){
             
request=new ActiveXObject("Microsoft.XMLHTTP");
         
}
      }
      //the request could still be null if neither ActiveXObject
      //initialization succeeded
      if(request){
         
initReq(reqType,url,asynch);
      } else {
          alert("Your browser does not permit the use of all "+
                "of this application's features!");
      }
  }
 /* Initialize a request object that is already constructed */
  function initReq(reqType,url,bool){
      /* Specify the function that will handle the HTTP response */ 
  request.onreadystatechange=handleResponse;
      request.open(reqType,url,bool);
      request.send(null); 
  
}

“Use the Request Object to POST Data to the Server” [Hack #2] shows how to implement a POST request withXMLHttpRequest.  


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials