jQuery Ajax error handling, show custom exception messages

前端 未结 21 2803
滥情空心
滥情空心 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:26

     error:function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
          }
    in code error ajax request for catch error connect between client to server if you want show error message of your application send in success scope

    such as

    success: function(data){
       //   data is object  send  form server 
       //   property of data 
       //   status  type boolean 
       //   msg     type string
       //   result  type string
      if(data.status){ // true  not error 
             $('#api_text').val(data.result);
      }
      else 
      {
          $('#error_text').val(data.msg);
      }
    
    }

提交回复
热议问题