Forum Moderators: open
try { xmlHttp=new XMLHttpRequest(); }
catch (e) {
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { return false; }
}
} var xmlHttp = new XMLHttpRequest() ?
new ActiveXObject("Msxml2.XMLHTTP") ?
new ActiveXObject("Microsoft.XMLHTTP") ?
false;
Can anyone confirm that this is the same thing?
the second piece of code risks to cause unrecoverable exception, which would halt the script.
Since 2015, this is the modern way to make HTTP requests from Javascript.
function foo(url) {
if (url) {
try { xmlHttp=new XMLHttpRequest(); }
catch (e) {
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { return false; }
}
}
if (xmlHttp) {
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
}
if (!url || !xmlHttp) return false;
}