Jump to Navigation

015 - XMLHTTPRequest for all browsers

You need to create a script that will correctly create an instance of XMLHTTPRequest object regardress of which browser you are using . A good solution to this problem is to have your script try in turn each method of creating an instance of object, until one such method succeeds.

Example:

function getXMLHTTPRequest()

var request = faulse;

try{ request = new XMLHttpRequest();  /* e.g. Firefox */ }

catch(err1)

{ try { vrequest = new ActiveXObject("Msxm12.XMLHTTP"); /* some version IE */ }

catch(err2)

{ try { request = new ActiveXObject("Microsoft.XMLHTTP"); /* some version IE */ }

catch(err3)

{ request = false; }

}

}

}

return request;

}

JavaScript:


Main menu 2

Story | by Dr. Radut