IE不会触发jQuery Ajax的成功

Pet*_*ter 14 ajax jquery internet-explorer

我正在编写一个脚本来使用jQuery加载一些异步图像.

这是加载图像的函数的代码片段 -

try{
    for(img in imgsArray){
        $.ajax({    
            async: false,
            type: "get",
            url:imgsArray[img],
            success:function(imgFile){
                alert("success");
                //do something useful
            },
            error:function(XMLHttpRequest,status,error){
                //do nothing
            }
        });//ajax
    } 
}
catch(e){
    //oops
}
Run Code Online (Sandbox Code Playgroud)

我已经在Firefox,Webkit(Safari,Chrome)中对此进行了测试,但它确实有效.

图像位于服务器上的文件夹中,我正在使用jQuery 1.3.

有任何想法吗?

小智 17

此问题的一个简单的解决方法是提供了jQuery设置dataType : 'text'dataType : 'xml'dataType : 'json'或任何其他可用的响应类型.

我有同样的问题,但在.ajax调用中指定dataType设置后它工作正常.

IE实际上不是智能浏览器,它不假设默认值字符串.

试试吧......祝你好运.


Joh*_*nes 11

尝试将cached-option设置为false.

   $.ajax({        
            async: false,
            cache: false, 
            type: "get",
            url:imgsArray[img],
            success:function(imgFile){
                    alert("success");
                    //do something useful
                    },
                    error:function(XMLHttpRequest,status,error){
                    //do nothing
            }
    });//ajax
Run Code Online (Sandbox Code Playgroud)


小智 7

我遇到了类似的问题 - 如果IE无法将响应解析为xml,IE似乎会触发失败,即使请求是成功的,所以如果您要请求图像,例如,它将返回xhr.status错误块中的200.

我在FF的成功块中以及在"if(xhr.status == 200)"条件中包含的错误块中保留了我的"成功"功能.