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
-
Include Javascript File in Another Javascript File
22 Mar 2024 -
Javascript: How Closures Work
22 Mar 2024 -
Javascript: Redirect to another webpage with Javascript and jQuery
22 Mar 2024 -
Javascript: Check if string contains a substring
21 Mar 2024 -
JavaScript: How to Print to Console, console.log, console.error, console.debug
06 Dec 2023 -
How to Hide a Column in AG-Grid and Prevent it from Displaying in the Tool Panel
11 Oct 2023