JQuery Ajax 在 IE10 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18764885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:27:21  来源:igfitidea点击:

JQuery Ajax not working in IE10

jqueryinternet-explorer-10jquery-file-uploadjquery-forms-plugin

提问by Ganesh Bhosle

Background

背景

I want to submit a form, stay on the same page & get the response.

我想提交一个表格,停留在同一页面上并得到回复。

Below mentioned code works perfectly in Chrome, Safari & Firefox. However It doesn't work in IE10.

下面提到的代码在 Chrome、Safari 和 Firefox 中完美运行。但是它在 IE10 中不起作用。

How to make it work in IE10?

如何使它在 IE10 中工作?

My Analysis correctness="questionable"

我的分析正确性=“有问题”

In IE10, $('#amazonUpload').ajaxSubmit(options)is executed, however No Ajax request is received at Server, hence response is never received at client.

在 IE10$('#amazonUpload').ajaxSubmit(options)中执行,但是服务器端没有收到 Ajax 请求,因此客户端永远不会收到响应。

HTML

HTML

<form action="https://s3.amazonaws.com/adminportal" enctype="multipart/form-data" id="amazonUpload" method="post">   
    <input name="key" type="hidden" value="001e0000009vkRLAAY/Forms/${filename}" />             
    <input name="AWSAccessKeyId" type="hidden" value="client aws key" /> 
    <input name="policy" type="hidden" value="really long string" /> 
    <input name="signature" type="hidden" value="sign value=" />             
    <input name="acl" type="hidden" value="private" /> 
    <input name="Content-Type" type="hidden" value="application/octet-stream"/>
    <div id="uploadPage:block:j_id31"><div class="pbSubsection">      
    <input id="uploadfileOne" name="file" required="True" size="25" type="file" />
    <input class="btn" id="myBtnId55" name="myBtnId55" onclick="uploadActComplete();" style="display:none;" type="button" value="Upload" />     
</form>

JavaScript

JavaScript

function uploadActComplete(){
    loading();     
    var options = { 
    //      error: errorResponse,
    //       success: successResponse,
    complete: function(xhr, status) {
        alert('status is :- '+status );
        if(status =='success')
            successResponse(xhr, status);
        else if(status =='error')
            errorResponse(xhr, status);
    }
    }; 
    $('#amazonUpload').ajaxSubmit(options); 
    return false;
}

function errorResponse(xhr, status)  {     
    stoploading();    
    alert('File could not be uploaded, please try again.'); 
} 
function successResponse(xhr, status)  {     
    stoploading();    
    $("input[id$='invisiblesubmit']").click();
}

回答by Sunil Verma

I have tried replicating your code on my system. and it works like a charm..

我试过在我的系统上复制你的代码。它就像一个魅力..

i have used following jquery files to achieve the above functionality.

我使用以下 jquery 文件来实现上述功能。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script>

Please check if you are using correct jquery files.

请检查您是否使用了正确的 jquery 文件。

I have also tried posting to a local file and ajax request was correctly received there.

我还尝试发布到本地文件,并且在那里正确接收了 ajax 请求。

回答by TheAshwaniK

Did you try this?

你试过这个吗?

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" >

More info here: http://code.gishan.net/code/solution-to-ie10-ajax-problem/

更多信息:http: //code.gishan.net/code/solution-to-ie10-ajax-problem/

@Daniel Schwarz, also answered. :)

@Daniel Schwarz,也回答了。:)

回答by amrinder007

Try adding meta tag inside head tag of your page which worked for me:-

尝试在页面的 head 标签中添加元标签,这对我有用:-

<meta http-equiv="x-ua-compatible" content="IE=9" >

IE10 works like IE9

IE10 像 IE9 一样工作

回答by Dave Hilditch

Use fiddler to analyse your ajax calls - it'll tell you if the call was made or not for sure.

使用 fiddler 分析您的 ajax 调用 - 它会告诉您是否确实进行了调用。

回答by Daniel Schwarz

A follow up to @amrinder007's answer, you could try this slight variation

跟进@amrinder007 的回答,你可以试试这个轻微的变化

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

Else there are other options that might work:

否则,还有其他可能有效的选项:

"IE=edge"
"IE=10"
"IE=EmulateIE10"
"IE=9"
"IE=EmulateIE9
"IE=8"
"IE=EmulateIE8"
"IE=7"
"IE=EmulateIE7"
"IE=5"

回答by Pranav Singh

I faced the similar situation with IE 10 only. In subsequent request with no change in parameter is not sent to server & considered as cached one.

我只在 IE 10 上遇到过类似的情况。在参数没有变化的后续请求中,不会发送到服务器并被视为缓存请求。

The solution in my case was to sending back a Cache-Control: no-cacheheader from your server. It provides a cleaner separation of concerns.

在我的情况下,解决方案是Cache-Control: no-cache从您的服务器发回标头。它提供了更清晰的关注点分离。

In ASP.Net I need to add

在 ASP.Net 我需要添加

HttpContext.Current.Response.AddHeader("Cache-Control", string.Empty);

Or

或者

HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");

OR

或者

Response.AppendHeader("Cache-Control", "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1    

It resolved the problem.

它解决了问题。

回答by Nick

You could append a timestamp to the end of URL being requested as a GET parameter. This is how I've gotten around IE's caching.

您可以将时间戳附加到作为 GET 参数请求的 URL 的末尾。这就是我绕过 IE 缓存的方式。

var date = new Date();
var options = { 
    url: $('#amazonUpload').attr('action')+'?time='+date.getTime(),
    // Your other options
}
$('#amazonUpload').ajaxSubmit(options); 
return false;

回答by QuadRunner

The biggest problems I have found with IE 10+ is the version of JQuery that you use. Since you haven't said which version you are using you should verify that you are using a JQuery 2.X version.

我在 IE 10+ 中发现的最大问题是您使用的 JQuery 版本。由于您没有说明您使用的是哪个版本,您应该验证您使用的是 JQuery 2.X 版本。

The Jquery 1.X Branch is for IE Browsers version 8 or less. The JQuery 2.X branch is for IE9+ browsers, Chrome, and FF. I haven't tried it with Safari.

Jquery 1.X Branch 适用于 IE 浏览器版本 8 或更低版本。JQuery 2.X 分支适用于 IE9+ 浏览器、Chrome 和 FF。我还没有用 Safari 尝试过。

Also verify that the version of Jquery Forms you are using is compatible with JQuery 2.x

还要验证您使用的 Jquery Forms 版本是否与 JQuery 2.x 兼容

For more information read the information on the JQuery download page at jquery.com/download

有关更多信息,请阅读jquery.com/download上的 JQuery 下载页面上的信息