weixin_33712987 2015-09-02 08:41 采纳率: 0%
浏览 50

AJAX响应失败

When we make any AJAX request, what are the different possibilities for the response failing and how do we verify it on client-side? Is it purely based on "response.status" I am using DOJO and see one place where I am getting response from the server, but response.status is "undefined" (dojo.xhrPost response)

More importantly technically speaking from the backend/server-side, do we have to explicitly do/pass something to indicate response failure on the client-side OR is that automatically handled (assume Java in the backend)?

  • 写回答

2条回答 默认 最新

  • weixin_33733810 2015-09-02 08:49
    关注

    The whole HTTP state is based on the status of the HTTP call. The server side component should be able to send the right failure response code/HTTP Status 4xx/5xx as expected. This is irrespective of the type of server/client side component.

    However, not all the failure cases needs to throw 5xx or 4xx status. For example, you may try to add a new record, if record already exists, the server can still send 200 OK response and give message stating - Record already available.

    It's all with the webdeveloper's discretion :)

    评论

报告相同问题?