I just need the clear explanation o开发者_StackOverflowf the below code for creating XMLHttpRequest
.
var xhr = false;
if (window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
It tries to create a native XMLHttpRequest
object and if that fails (ancient IE versions), it tries to use the XHR ActiveX object.
Note that it would be good to use e.g. jQuery for AJAX - it wraps it nicely, makes your code much more readable and saves you lots of work.
精彩评论