Java – jQuery Ajax error resolution

I'm developing a striped application that uses some jQuery to make the UI more dynamic / usable

I set up an error resolution, so if an error is thrown, the user will be redirected to error JSP page

However, if an error is thrown during a jQuery Ajax call instead of redirecting to error JSP page, I will print HTML to the page that should call the result

If you throw an exception instead of printing to the page, how do you tell jQuery to redirect?

An example of Ajax violation:

$.post("SendStatusEmail.action",{status: newstatus,id : id },function(data) {
                column.text(data);
                column.addClass("redfont");
                column.parent().fadeOut(3000,function(){column.parent().remove()});

Solution

$(document).ajaxError(function(event,XMLHttpRequest,ajaxOptions,thrownError) {
$(document).ajaxError(function(event,XMLHttpRequest,ajaxOptions,thrownError) {
    // redirect here.
}

I should add that I don't redirect when there are exceptions in Ajax calls Instead, I ask the server to return the error description in JSON format and display it on the page

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>