开发者

How to create XMLHttpRequest

开发者 https://www.devze.com 2023-03-02 20:15 出处:网络
I just need the clear explanation o开发者_StackOverflowf the below code for creating XMLHttpRequest.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消