onreadystatechange在IE中不起作用 [英] onreadystatechange is not working in IE

查看:311
本文介绍了onreadystatechange在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript函数下方上传所选文件并更新网格。它在firefox和chrome中完美运行,但在IE11中却没有。观察到它没有在onreadystatechange中执行ESignature / Registration功能。我在注册功能上保持了突破点。它没有受到打击而没有刷新网格。



令人惊讶的是,当我在IE中按F12打开调试器时它正在工作。如果我关闭它,它再次无法正常工作。有点奇怪

请指导我解决这个问题。



 $(  #lnkAddAttachment)。click( function (e){
if document .getElementById( txtFile)。files [ 0 ]!= null ){
oFiles = document .getElementById( txtFile)。files [ 0 ];
nFiles = oFiles.size;

var selectedFile = document .getElementById( tx tFile)。files [ 0 ];
var xhr = new XMLHttpRequest();
var fd = new FormData();
var url = ' @ Url.Content (〜/)' + ESignature / getFile;

fd.append( file document .getElementById(' txtFile')。files [ 0 ]);
$( #loadingwrapper)。fadeIn();
xhr.onreadystatechange = function (){
if (xhr.readyState = = 4 ){
var url1 = ' @ Url.Content(〜/)' + 电子签名/注册 ;
$(' #gridAttachments')。load(url1 + ' #gridAttachments');
$( #loadingwrapper)。fadeOut();
}
};
xhr.open( POST,url,);
xhr.send(fd);
$(' #txtDescription')。val(' ');
$(' #txtFile')。val(' ');

return false ;
}
});

解决方案

#lnkAddAttachment)。click( function (e){
if document .getElementById( txtFile)。files [ 0 ]!= null ){
oFiles = document .getElementById( txtFile )。files [ 0 ];
nFiles = oFiles.size;

var selectedFile = document .getElementById( txtFile)。文件[<跨度类= 代码位> 0 ];
var xhr = new XMLHttpRequest();
var fd = new FormData();
var url = ' @ Url.Content (〜/)' + ESignature / getFile;

fd.append( file document .getElementById(' txtFile')。files [ 0 ]);


#loadingwrapper)淡入();
xhr.onreadystatechange = function (){
if (xhr.readyState = = 4 ){
var url1 = ' @ Url.Content(〜/)' + ESignature / Registration;


' #gridAttachments')。load(url1 + ' #gridAttachments');

Below javascript function uploads the chosen file and updates the grid. Its working perfectly in firefox and chrome but not in IE11. Observed that its not executing "ESignature/Registration" function in onreadystatechange. I kept break point at Registration function. Its not getting hit and not refreshing the grid.

Surprisingly, its working when I open the Debugger by pressing F12 in IE. If I close it, again its not working. Something strange
Please guide me to fix this problem.

$("#lnkAddAttachment").click(function (e) {
            if (document.getElementById("txtFile").files[0] != null) {
                oFiles = document.getElementById("txtFile").files[0];
                nFiles = oFiles.size;

                var selectedFile = document.getElementById("txtFile").files[0];                
                var xhr = new XMLHttpRequest();
                var fd = new FormData();
                var url = '@Url.Content("~/")' + "ESignature/getFile";

                fd.append("file", document.getElementById('txtFile').files[0]);
                $("#loadingwrapper").fadeIn();
                xhr.onreadystatechange = function () { 
                    if (xhr.readyState == 4) {                       
                        var url1 = '@Url.Content("~/")' + "ESignature/Registration";
                        $('#gridAttachments').load(url1 + ' #gridAttachments');
                        $("#loadingwrapper").fadeOut();
                    }
                };
                xhr.open("POST", url, true);
                xhr.send(fd);
                $('#txtDescription').val('');
                $('#txtFile').val('');

                return false;
            } 
        });

解决方案

("#lnkAddAttachment").click(function (e) { if (document.getElementById("txtFile").files[0] != null) { oFiles = document.getElementById("txtFile").files[0]; nFiles = oFiles.size; var selectedFile = document.getElementById("txtFile").files[0]; var xhr = new XMLHttpRequest(); var fd = new FormData(); var url = '@Url.Content("~/")' + "ESignature/getFile"; fd.append("file", document.getElementById('txtFile').files[0]);


("#loadingwrapper").fadeIn(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { var url1 = '@Url.Content("~/")' + "ESignature/Registration";


('#gridAttachments').load(url1 + ' #gridAttachments');


这篇关于onreadystatechange在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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