简体   繁体   中英

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. If I send the param like this

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

Thanks in advance.

GET requests are not expected to have bodies.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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