Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding json to jquery ajax GET request
    primarykey
    data
    text
    <p>I want to use jQuery's ajax call with type 'GET' against my RESTful API running on Flask. In my request I want to post some data as JSON.</p> <p>I'm doing the exact same thing for POST requests and they work like charm. But with GET Flask gives me 400 errors and looking deeper into it it seems that the JSON gets partly URIEncoded on the way ({%22email%22:%22some@email.com%22}).</p> <p>I've tried to use decodeURIComponent as I'm JSON.stringifying the json in the ajax data parameter but makes no difference.</p> <pre><code>sessiontoken = "123abc"; jsonData = {"email": email}; $.ajax({ type: 'GET', crossDomain: true, url: 'http://someserver/sessions/' + sessiontoken, dataType: 'json', processData: false, //added this to see if it helps, it didn't contentType: "application/json", async: false, data: JSON.stringify(jsonData), success: function(data){ //I'd be happy }, error: function(data){ //This is where I get as my backend throws a 400 on me due to the screwed up json } }); </code></pre> <p>It's driving me nuts as I can't seem to find anyone on the planet who's had the same issue. I've been ajaxing requests before and never faced this silly thing in the past.</p> <p>Edit: Ok it seems like I need to give up on my goal and just pass whatever parameters as query string instead of trying to add them to the request body. I guess there is nothing wrong with that as discussed for example here: <a href="https://stackoverflow.com/questions/4024271/rest-api-best-practices-where-to-put-parameters/4026505#4026505">REST API Best practices: Where to put parameters?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload