$.post() doesn't send data as json but as x-www-form-urlencoded instead

后端 未结 4 1142
傲寒
傲寒 2020-12-14 00:11

This one is really weird. I\'ve multiple $.post() in the code but there is one dunno why sends the json parameters as x-www-form-urlencoded instead

4条回答
  •  被撕碎了的回忆
    2020-12-14 00:30

    Because $.post() is for sending form-like requests. $.ajax is for sending whatever you want to. See contentType in $.ajax page for more information.

    Quote:

    When sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases. If you explicitly pass in a content-type to $.ajax() then it'll always be sent to the server (even if no data is sent). Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side.

提交回复
热议问题