3
$.get ("/asd", {
    asd: "foo"
}, function (res){
    alert ("ok");
});

This sends the parameters in the querystring:

/asd?asd=foo

But I just need to use the http body to send the json object:

{ "asd": "foo" }
Gabriel Llamas
  • 18,244
  • 26
  • 87
  • 112
  • Body will be in POST request. Try to use jQuery.post(). But body will be in urlencoded string. – Victor Apr 04 '13 at 11:36
  • But I need to send a GET request. – Gabriel Llamas Apr 04 '13 at 11:38
  • I have found: http://stackoverflow.com/questions/10298899/how-to-send-data-in-request-body-with-a-get-when-using-jquery-ajax – Victor Apr 04 '13 at 11:45
  • If it is very important you can create server side part which will take your GET request, open socket to destination site and put there GET request and converted data from GET parametrs in the body. – Victor Apr 04 '13 at 11:53
  • Ok, it seems that sending an http body with get it's not the way to go. I'll change it to post. – Gabriel Llamas Apr 04 '13 at 12:44

1 Answers1

0

If you want to send a JSON object then you should really be using POST. However, if you absolutely need to use GET, you can do:

$.get ("/asd", { json: JSON.stringify({asd: "foo"}) }, function (res){
    alert ("ok");
});

This will convert the JSON object into a string and pass it into the json GET parameter (be cautious, JSON.stringify does not work on older browsers).

alexpls
  • 1,914
  • 20
  • 29