使用 jquery 的 AJAX https POST 请求在 Firefox 中失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/597073/
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 09:25:43  来源:igfitidea点击:

AJAX https POST requests using jquery fail in Firefox

jqueryajaxfirefoxfirefox-3

提问by MikeN

I have a simple list of records in an HTML table with a delete link for each row. The delete link shoots off an AJAX post request to a fixed url that looks like: "/delete/record/5"

我在 HTML 表中有一个简单的记录列表,每行都有一个删除链接。删除链接将 AJAX 发布请求发送到一个固定的 url,如下所示:“ /delete/record/5

The AJAX request is created using jquery's .ajax()call with a POST message when running on a server that uses https. This call fails in Firefox 3 on OSX/Windows architectures. It works on all other browsers I've tested (OSX/Windows: Chrome, Safari, IE7.)

.ajax()使用 https 的服务器上运行时,AJAX 请求是使用 jquery调用和 POST 消息创建的。此调用在 OSX/Windows 架构上的 Firefox 3 中失败。它适用于我测试过的所有其他浏览器(OSX/Windows:Chrome、Safari、IE7。)

The requests are coming from an https site and going to the same https site. But I think somewhere during the process the original request starts off as http and there is a redirect attempt on our server to send it from http->https and Firefox rejects that redirect as some type of forgery.

请求来自 https 站点并转到同一个 https 站点。但我认为在这个过程中的某个地方,原始请求以 http 开始,我们的服务器上有一次重定向尝试从 http->https 发送它,Firefox 拒绝该重定向作为某种类型的伪造。

Has anyone had experience doing .ajax()JQuery calls on an https site with Firefox? I notice something odd where if the request has "?var=xxx" arguments in the URL, the request seems to work more often then if it does not have those variables.

有没有人有过.ajax()使用 Firefox 在 https 站点上调用 JQuery 的经验?我注意到一些奇怪的地方,如果请求?var=xxx在 URL 中有“ ”参数,那么如果没有这些变量,请求似乎更频繁地工作。

回答by alex2k8

Sounds like you're getting an HTTP 411 error.. This error can happen if you're sending a POSTrequest without any data.

听起来您收到了 HTTP 411 错误。. 如果您发送的POST请求没有任何data.

To fix this, add an empty object ({}) to the dataproperty to your requests:

要解决此问题,请将一个空对象 ( {})添加data到您的请求的属性中:

$.ajax({ 
    url: url, 
    type: 'POST', 
    data: {}, // <- set empty data 
    success: function(data, textStatus) { 
        // do something 
    } 
}); 

回答by Spencer Ruport

That seems unlikely... not that I'm doubting you. But I would suggest downloading Wireshark and watching your HTTP traffic to see if you can't isolate the problem. You'll be able to compare the request sent by other browsers against the request sent out by FF3 and see what sort of response is coming back. If it is indeed a problem with jQuery not functioning correctly in FF3 you might be able to alter some of the code to work properly.

这似乎不太可能……不是我在怀疑你。但我建议下载 Wireshark 并观察您的 HTTP 流量,看看您是否无法隔离问题。您将能够将其他浏览器发送的请求与 FF3 发送的请求进行比较,并查看返回的响应类型。如果确实是 jQuery 在 FF3 中无法正常运行的问题,您也许可以更改某些代码以使其正常工作。

回答by alexpopescu

You can probably install the Firefox Live Headers extension that will give you access to all the information in your requests/responses. This way you'll be catch any differences.

您可以安装 Firefox Live Headers 扩展,它可以让您访问请求/响应中的所有信息。这样你就会发现任何差异。

回答by ceejayoz

Do you have any plugins or GreaseMonkey scripts installed on your Firefox?

您的 Firefox 上是否安装了任何插件或 GreaseMonkey 脚本?

I have never had issues with jQuery AJAX requests on HTTPS. I'd suggest taking a look at what Firebugturns up if you haven't already.

我从来没有在 HTTPS 上遇到过 jQuery AJAX 请求的问题。如果您还没有,我建议您看看Firebug会出现什么。

回答by ctsears

I got $.postto work in Firefox by sending an empty object as the dataparameter. Notice the empty brackets for parameter 2:

$.post通过发送一个空对象作为data参数来在 Firefox 中工作。注意参数 2 的空括号:

$.post(url, {}, function(response){ alert('done'); }, "json");