View Single Post
Old 02-13-2013, 10:58 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,064 Times in 4,033 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
As Felgall said.

One better way (and there are others, but this works for me) is:
Code:
function createRequestObject() {
    return   ( XMLHttpRequest != null )
           ? new XMLHttpRequest( ) 
           : new ActiveXObject("Microsoft.XMLHTTP");
}
Another seemingly popular way:
Code:
function createRequestObject() 
{
    try {
        return  new XMLHttpRequest();
    } catch ( ignored ) { }
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
   } catch ( oops ) {
        return null;
   }
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote