Proper status codes for JSON responses to Ajax calls?

前端 未结 2 1315
遇见更好的自我
遇见更好的自我 2021-02-01 03:48

My project is returning JSON to Ajax calls from the browser. I\'m wondering what the proper status code is for sending back with responses to invalid (but successfully handled)

2条回答
  •  梦如初夏
    2021-02-01 04:08

    I would send a '400 Bad Request' header back in response with information in json of what went wrong. Then catch the event with jquerys $.ajaxError() event handler and parse the error message i got in return to deliver good feedback to the end user.

    You can read more about the ajaxError event handler here!

提交回复
热议问题