如何在jQuery ajax中使用GET请求发送原始数据? [英] How to send the raw-data with GET request in jQuery ajax?

查看:52
本文介绍了如何在jQuery ajax中使用GET请求发送原始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,有了新的API,我只有一个url和一些参数.如果我发送这样的参数

Now, there is new API and I got just a url and some parameters. If I send the param like this

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

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

然后这不起作用.但是,如果我以原始数据的形式发送POSTMAN数据,则它可以正常工作.GET请求不应包含主体.但是我已经使用cURL在PHP中实现了相同的功能,并使用原始数据创建了自定义GET请求.我不知道如何在jQuery AJAX中实现相同的功能.请帮忙.

then this doesn't work. But if I send in POSTMAN data as raw-data, then it's working. GET requests are not expected to have bodies. But I have implemented the same in PHP using cURL and created custom GET request with raw-data. I don't know how to implement the same in 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);
});

谢谢.

推荐答案

GET请求不应包含正文.

GET requests are not expected to have bodies.

是真的.HTTP规范中明确未定义带有主体的GET请求的行为.

This is true. The behaviour of a GET request with a body is explicitly undefined in the HTTP specification.

XMLHttpRequest(jQuery Ajax使用的底层API)不支持发送带有GET请求的请求正文.

XMLHttpRequest (the underlying API used by jQuery Ajax) does not support the sending of a request body with a GET request.

执行此操作的唯一方法是通过服务器代理请求.

The only way to do this would be to proxy the request through your server.

这篇关于如何在jQuery ajax中使用GET请求发送原始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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