jQuery Ajax error handling, show custom exception messages

前端 未结 21 3098
滥情空心
滥情空心 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条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 02:29

    $("#fmlogin").submit(function(){
       $("#fmlogin").ajaxError(function(event,xhr,settings,error){
           $("#loading").fadeOut('fast');       
           $("#showdata").fadeIn('slow');   
           $("#showdata").html('Error please, try again later or reload the Page. Reason: ' + xhr.status);
           setTimeout(function() {$("#showdata").fadeOut({"opacity":"0"})} , 5500 + 1000); // delays 1 sec after the previous one
        });
    });
    

    If there is any form is submit with validate

    simply use the rest of the code

    $("#fmlogin").validate({...
    

    ... ... });

提交回复
热议问题