ASP.NET Atlas is full of JavaScript goodness
I was looking through the JavaScript code for Atlas and I noticed there is some pretty neat stuff in there. It is really a very large enhancement to JavaScript.
One of the things I noticed is they are adding support for the XMLHttpRequest object if the browser doesn’t natively support it. In the past I’ve traditionally just created a function named similarly to ‘CreateXMLHttpRequestObject’ and I make that function support multiple browsers. The technique that’s used in Atlas is they are adding the ‘window.XMLHttpRequest’ object if it doesn’t already exist. This allows for your AJAX code to support multiple browsers more easily by making it so you don’t need to change your code to support Internet Explorer. And your code will still work in IE7 because IE7 natively supports the ‘window.XMLHttpRequest’ object. Very nice guys!
Below is the above mentioned chunk of JS code for your viewing pleasure:
//-----------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------
// Atlas.js
// Atlas Framework.
//
if (!window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];
for (var i = 0; i < progIDs.length; i++) {
try {
var xmlHttp = new ActiveXObject(progIDs[i]);
return xmlHttp;
}
catch (ex) {
}
}
return null;
}
}
Remember the above code is technically copyrighted to Microsoft and is part of the Atlas Framework.
Related Posts
-
How to Hide a Column in AG-Grid and Prevent it from Displaying in the Tool Panel
11 Oct 2023 -
JavaScript: Loop through Array (using forEach)
03 Oct 2023 -
JavaScript: Parse a String to a Date
28 Sep 2023 -
JavaScript: Format Date to String
28 Sep 2023 -
JavaScript: How to Convert Map to an Array of Objects
28 Sep 2023 -
Check if element exists using JavaScript or jQuery
25 Sep 2023