IE中未针对XHR请求触发onReadyStateChange [英] onReadyStateChange not firing in IE for XHR Request

查看:347
本文介绍了IE中未针对XHR请求触发onReadyStateChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在使用的这段代码,它在chrome中可以正常工作,但是在IE中,似乎onreadystatechenge没有触发.

I have this code that I am using and it works fine in chrome, but in IE, it looks like that onreadystatechenge is not firing.

如何使它跨浏览器工作.我读到在IE中必须将onreadystatechange事件放置在发送之前,但这没用.

How do I get this to work cross browser. I read that in IE you have to place the onreadystatechange event before the send, But that didn't work.

此处的警报未触发.是的,它是成功的.

The alert here is not firing. And yes it is successful.

if (xhr.status==200 && xhr.readyState==4)
    {
        alert("DONE!");
    }

这是整个请求.

function SendFile(evt)
{
var xhr = new XMLHttpRequest();
var data = new FormData();
var files = $("#FileUpload1").get(0).files;

for (var i = 0; i < files.length; i++)
{

    data.append(files[i].name, files[i]);
}
xhr.upload.addEventListener("progress", function (evt)
{
    if (evt.lengthComputable)
    {
        var progress = Math.round(evt.loaded * 100 / evt.total);
        $("#progressbar").progressbar("value", progress);
    }
}, false);
xhr.open("POST", "Handler.ashx");

xhr.onreadystatechange=function ()
{
    if (xhr.status==200 && xhr.readyState==4)
    {
        alert("DONE!");
    }
}
xhr.send(data);


$("#progressbar").progressbar({
    max: 100,
    change: function (evt, ui)
    {
        $("#progresslabel").text($("#progressbar").progressbar("value") + "%");
    },
    complete: function (evt, ui)
    {
        $("#progresslabel").text("File upload successful!");
        GetID();
    }
});

}

尝试加载时没有运气.

   xhr.onload = function ()
    {
        if (xhr.readyState == 4 && xhr.status==200)
        {
            alert("IE DONE!");

        }
    }

推荐答案

您的XMLHttpRequest对象可能正在缓存.

Your XMLHttpRequest object might be caching.

尝试:

var myNoCachePage = document.location + '?' + new Date().getTime();
xhr.open("GET", myNoCachePage, true);  // Prevent IE11 from caching
xhr.send();

这篇关于IE中未针对XHR请求触发onReadyStateChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆