jQuery Ajax error handling, show custom exception messages

前端 未结 21 2805
滥情空心
滥情空心 2020-11-22 01:50

Is there some way I can show custom exception messages as an alert in my jQuery AJAX error message?

For example, if I want to throw an exception on the server side v

21条回答
  •  梦毁少年i
    2020-11-22 02:22

    jQuery.parseJSON is useful for success and error.

    $.ajax({
        url: "controller/action",
        type: 'POST',
        success: function (data, textStatus, jqXHR) {
            var obj = jQuery.parseJSON(jqXHR.responseText);
            notify(data.toString());
            notify(textStatus.toString());
        },
        error: function (data, textStatus, jqXHR) { notify(textStatus); }
    });
    

提交回复
热议问题