$就忽略数据参数的DELETE请求 [英] $.ajax ignoring data param for DELETE requests

查看:219
本文介绍了$就忽略数据参数的DELETE请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新的jQuery的1.3.2至1.4.3,和我看到了一些新的行为使得AJAX DELETE请求时。出于某种原因,数据传递在我的数据参数不被发送到服务器。例如:

I just updated from jQuery 1.3.2 to 1.4.3, and I'm seeing some new behavior when making AJAX DELETE requests. For some reason, the data being passed in my data parameter is not being sent to the server. For example:

$.ajax({
    url: '/example',
    data: {id: 12},
    type: 'DELETE'
});

最终把删除发送请求 /例如,没有额外的数据。然而,这种类型的呼叫参数传递就好了:

Ends up sending a DELETE request to /example with no additional data. However, this type of call passes the parameters just fine:

$.ajax({
    url: '/example?id=12',
    type: 'DELETE'
});

有其他人看到类似的行为?还有一个原因是,这是不再工作(即:这是由设计,或者是一个bug)?如何得到它的工作有什么建议?

Has anyone else seen similar behavior? Is there a reason this is no longer working (i.e.: is it by design, or is it a bug)? Any suggestions on how to get it working?

另外,如果你想知道为什么我不只是想传递参数的URL字符串的一部分,这是因为我最终尝试使用 $。ajaxSetup 回调,提供了一些常规参数存在(即 authenticity_token 参数一起使用,以防止伪造Rails中)。这一切都在尝试的jQuery 1.4.3正常工作之前。

Also, in case anyone is wondering why I don't simply want to pass the parameters as part of the URL string, it's because I'm ultimately attempting to use the $.ajaxSetup callback, providing some general parameters there (namely the authenticity_token parameter used to protect against forgery in Rails). This all worked fine prior to trying jQuery 1.4.3.

推荐答案

jQuery的只会追加参数的查询字符串为 GET 只请求(和的没有机构删除要求),所以这是jQuery的1.4.3故意行为。

jQuery will only append parameters to the querystring for GET requests only (and no body for DELETE requests), so this is intentional behavior in jQuery 1.4.3.

然而,自那时以来的变化(提交这里)允许机构删除要求在1.4.4版本。

However, there is a change since then (commit here) to allow a body for DELETE requests in the 1.4.4 release.

这篇关于$就忽略数据参数的DELETE请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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