我正在使用这段代码,它在 chrome 中工作正常,但在 IE 中,看起来 onreadystatechange 没有触发。
我如何让它跨浏览器工作。我读到在 IE 中你必须在发送之前放置 onreadystatechange 事件,但这不起作用。
这里的警报没有触发。是的,它是成功的。
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!");
}
}
Your XMLHttpRequest
对象可能正在缓存。
Try:
var myNoCachePage = document.location + '?' + new Date().getTime();
xhr.open("GET", myNoCachePage, true); // Prevent IE11 from caching
xhr.send();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)