In the follow ajax request could some one please explain (tryMS)
function createRequest() {
try {
request = new XMLHttpRequest();
} catch (tryMS) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (otherMS) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
return request;
}
Is (tryMS), and (otherMS) part of javascript or is it just a common argument used in the code, do they have specific functions? If its an argument wheres it value coming from.
In this case,
tryMSandotherMSare just variable names. You could replace them with any valid variable name and the logic would be exactly the same. In this case, the object they will represent at runtime is a subclass ofExceptionas they are used in the catch clause of a try-catch statement.You can read more about try-catch-finally here.
I wouldn’t agree with the naming convention being used here, but the variable name is essentially describing the flow of control based on the browser being used. For example, if the creation of an
XMLHttpRequestobject causes an exception to be raised, then we should try an AJAX technique for microsoft browsers usingActiveXObject– hence the nametryMS.