LoginSignup
3
3

More than 5 years have passed since last update.

Ajax の リクエストボディを JSON 形式する方法

Last updated at Posted at 2015-10-07

問題

下記の様な形式にした場合に、リクエストボディがJSON形式になっていなかった。

リクエストボディの設定
        :
data: {
    "name": name,
    "description": description
},
        :
実際に送られたリクエストボディの内容
name=xxx&description=yyy

対処方法

JSON.stringifyを使ってJSON形式に変換する。

リクエストボディの設定
        :
data: JSON.stringify({
    "name": name,
    "description": description
}),
        :
実際に送られたリクエストボディの内容
{"name":"xxx","description":"yyy"}

参考

ajax - jQuery posting valid json in request body - Stack Overflow:

以上。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3