LoginSignup
1
3

More than 5 years have passed since last update.

ajaxが常にエラーに入る原因と解決法

Last updated at Posted at 2017-06-03

ちゃんと実行したのになぜか常にajaxのerrorのところに入ってしまう経験ありませんか
調べたら、それはjquery 1.4以降だと、jsonの返り値に対して厳しくなったせいです。
つまり、入ったJSONは正しい形じゃなかったら、全部エラーとして処理する

こんな風に書けばいい

正解.php
  return json_encode(array("success"=>true));
  //or
  return json_encode(array("success"=>"true"));

他パラメーター増やしても良いが、必ず"success"=>trueを入れること

1
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
1
3