简体   繁体   English

如何在 jQuery ajax 中使用 GET 请求发送原始数据?

[英]How to send the raw-data with GET request in jQuery ajax?

Now, there is new API and I got just a url and some parameters.现在,有了新的 API,我只得到了 url 和一些参数。 If I send the param like this如果我这样发送参数

https://api.somthing.com/Search?zip= $zip&id=$id&key=$key https://api.somthing.com/Search?zip= $zip&id=$id&key=$key

then this doesn't work.那么这不起作用。 But if I send in POSTMAN data as raw-data, then it's working.但是,如果我将 POSTMAN 数据作为原始数据发送,那么它就可以工作了。 GET requests are not expected to have bodies. GET 请求不应该有正文。 But I have implemented the same in PHP using cURL and created custom GET request with raw-data.但是我在 PHP 中使用 cURL 实现了相同的功能,并使用原始数据创建了自定义 GET 请求。 I don't know how to implement the same in jQuery AJAX.我不知道如何在 jQuery AJAX 中实现相同的功能。 Please help.请帮忙。

I've tried something like this:我试过这样的事情:

var settings = {
  "url": url,
  "method": "GET",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "Cookie": "__cd=d311a6f2055dd5fb9462c000a297f4a0158451265"
  },
  "data": jsonData,
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Thanks in advance.提前致谢。

GET requests are not expected to have bodies. GET 请求不应该有正文。

This is true.这是真实的。 The behaviour of a GET request with a body is explicitly undefined in the HTTP specification. HTTP 规范中明确未定义带有主体的 GET 请求的行为。

XMLHttpRequest (the underlying API used by jQuery Ajax) does not support the sending of a request body with a GET request. XMLHttpRequest(jQuery Ajax 使用的底层 API)不支持使用 GET 请求发送请求正文。

The only way to do this would be to proxy the request through your server.这样做的唯一方法是通过您的服务器代理请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM