JQuery, send JSON object using GET method

前端 未结 4 1918
梦如初夏
梦如初夏 2020-12-14 15:41

I am trying to send a json object using GET method. My code:

$.ajax({
           url: \"/api/endpoint\",
           type: \"GET\",
           data: {\"sort\"         


        
4条回答
  •  感情败类
    2020-12-14 16:16

    There are a few places where you have gone a bit wrong.

    • It is not CONTENT_LENGTH, its Content-Length.
    • Do not set Content-Length header, the browser will do it for you.
    • Get request has content-length = 0.

    Something like the below should work for you:

    $.ajax({
         url: "/api/endpoint?parameters="+encodeURIComponent(JSON.stringify({"sort":"date"})),
         type: "GET",
         ...
    });
    

提交回复
热议问题