0

I am trying to develop a function to send json data via get method using javascript instead of curl.

And it also works fine with the get method of jquery ajax api.For example,

$.ajax({
    url     : url,
    type    : "GET",
    data    : json,
    dataType: "json",
    //.....
    //other code here.
})

But something wrong happened, when I try to send the same json data by the follow code as someone else suggest here.

xmlhttp.open("GET",url+"?pretty="+encodeURIComponent(JSON.stringify(json)),true);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.send();

However,it seems that the json data is too large to be encoded inside the url, and the url was truncated.

So, I wander how I can send the large json with javascript just as the jquery does.

Community
  • 1
  • 1
aMooly
  • 551
  • 5
  • 13
  • IS the server returning 414 (Request-URI Too Long) status i.e an URI is longer than the server can handle.? – Swaraj Aug 20 '14 at 10:10
  • No,the server return 200.I has used Wireshark to capture the packet, and the head of request packet shows just like "[truncated] OPTIONS (something else)", so I think that the request url has been truncated before being sent. – aMooly Aug 20 '14 at 10:44
  • There is a limit to send packet through url beyond which you need to use post. I guess it would be getting truncated after 255 characterss – Swaraj Aug 20 '14 at 10:55
  • Yep.But it's a little confused that I send the same size data by jquery's ajax api.And I wanna know how to send the json without jquery. – aMooly Aug 20 '14 at 16:46

0 Answers0