我使用的服务API有一个给定的GET方法,该方法要求在请求体中发送数据.

正文中所需的数据是由连字符分隔的id列表,可能非常大,因此必须在正文中发送,否则它很可能会出现在浏览器/代理/Web服务器等链中的某个位置.注意:我没有对服务或API的控制权,所以请不要建议更改它.

I am using the following jQuery code however observing the request/response in fiddler I can see that the "data" I am sending is ALWAYS converted and appended to the query string despite me setting the "processData" option to false...

$.ajax({
   url: "htttp://api.com/entity/list($body)",
   type: "GET",
   data: "id1-id2-id3",
   contentType: "text/plain",
   dataType: "json",
   processData: false, // avoid the data being parsed to query string params
   success: onSuccess,
   error: onError
});

有人知道我如何强制在请求正文中发送"数据"值吗?

推荐答案

一般来说,这不是系统使用GET请求的方式.所以,你的图书馆很难配合.事实上,spec表示,"如果请求方法是GET或HEAD的区分大小写的匹配,那么就好像数据为null一样."所以,我认为你运气不好,除非你使用的浏览器不尊重规范的这一部分.

您可以在自己的服务器上为POST Ajax请求设置一个端点,然后在服务器代码中将其重定向到带有正文的GET请求.

If you aren't absolutely tied to GET requests with the body being the data, you have two options.

POST with data: This is probably what you want. If you are passing data along, that probably means you are modifying some model or performing some action on the server. These types of actions are typically done with POST requests.

GET with query string data: You can convert your data to query string parameters and pass them along to the server that way.

url: 'somesite.com/models/thing?ids=1,2,3'

Jquery相关问答推荐

为什么如果使用转换规模,juserui可拖动遏制不起作用

使用jquery ui来回滑动切换

从克隆的输入中读取数据属性,返回初始输入的值

更改后如何使用 jQuery Select CSS 类

如何在外部JS文件中使用带有参数的laravel路由

将一个类动态添加到 Bootstrap 的popover容器中

将变量传递给jQuery AJAX成功回调中的函数

ASP .NET MVC 在每个字段级别禁用客户端验证

如何使用jQuery找到元素顶部的垂直距离(以px为单位)

子元素点击事件触发父点击事件

使用 jQuery 从 AJAX 响应(json)构建表行

Jquery - 如何获取样式显示属性无/块

使用 jquery 在 radio 上单击或更改事件

JQuery Ajax Post 导致 500 内部服务器错误

jQuery 不会从 AJAX 查询中解析我的 JSON

5秒后jQuery自动隐藏元素

如何在 jQuery 中 Select this中的元素?

你如何使用 jquery 淡入/淡出背景 colored颜色 ?

如何获得两个日期对象之间的小时差?

jQuery UI 选项卡 - 如何获取当前选定的选项卡索引