I have never been a fan of nested try / catch blocks, so I would do something like:
var xmlHttp; if (window.XMLHttpRequest) { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } if (xmlHttp) { // No errors, do whatever you need. }
I think it will work. But, as mentioned earlier, why reinvent the wheel, use the library. Better yet, find out how they do it.
Lee Theobald
source share