如何申请机身采用了GET使用jQuery $就当发送数据() [英] How to send data in request body with a GET when using jQuery $.ajax()

查看:112
本文介绍了如何申请机身采用了GET使用jQuery $就当发送数据()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该服务的API,我耗费了要求数据的请求主体发送一个给定的GET方法。

The service API I am consuming has a given GET method that requires the data be sent in the body of the request.

在体内所需的数据是由连字符分隔的ID的列表,并可能会非常大,因此它必须在体内被发送,否则它可能会在浏览器/代理/网络服务器等链某处FOOBAR。注意:我没有过服务或API控制,所以请不要提出建议,以改变它。

The data required in the body is a list of id's separated by hypen and could potentially be very large and thus it must be sent in the body otherwise it will likely foobar somewhere in the browsers/proxies/webservers etc chain. Note I don't have control over the service or API so please don't make suggestions to change it.

我使用下面的jQuery的code然而观察请求/响应的小提琴手,我可以看到数据我差始终转换并追加到查询字符串,尽管我的设置过程数据选项假...

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
});

任何人都知道我可以强制的数据值在请求主体发送? 任何援助AP preciated,在此先感谢。

Anyone know how I can force the "data" value to be sent in the body of the request? Any assistance is appreciated, thanks in advance.

推荐答案

在一般情况下,这不是系统如何使用GET请求。因此,这将是很难让你的图书馆一起玩。事实上,规范说:如果请求方法是一个个案敏感的匹配GET或HEAD的行为,如果数据为空。所以,我觉得你的运气了,除非您使用的浏览器不遵守规范的一部分。

In general, that's not how systems use GET requests. So, it will be hard to get your libraries to play along. In fact, the spec says that "If the request method is a case-sensitive match for GET or HEAD act as if data is null." So, I think you are out of luck unless the browser you are using doesn't respect that part of the spec.

您也许可以设置自己的服务器进行POST Ajax请求在端点上,然后重定向,在您的服务器code与身体的GET请求。

You can probably setup an endpoint on your own server for a POST ajax request, then redirect that in your server code to a GET request with a body.

如果你是不是绝对依赖于获得与身体之中的数据请求,你有两个选择。

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

POST数据:这可能是你想要的。如果你沿着传递数据,这可能意味着要修改一些模型或执行服务器上的一些动作。这些类型的操作典型的做法与POST请求。

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'

这篇关于如何申请机身采用了GET使用jQuery $就当发送数据()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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