jQuery Ajax error handling, show custom exception messages

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

    First we need to set in web.config:

     
      
       
        **** 
      
    
    

    In addition to that at jquery level in error part you need to parse error response that contains exception like:

    .error(function (response, q, t) { 
      var r = jQuery.parseJSON(response.responseText); 
    }); 
    

    Then using r.Message you can actully show exception text.

    Check complete code: http://www.codegateway.com/2012/04/jquery-ajax-handle-exception-thrown-by.html

提交回复
热议问题