在jquery ajax方法中出现问题捕获错误

时间:2022-10-28 13:32:12

I am using jquery ajax method on my aspx page to call a web method in the code behind.If the call fails,for any reason I would like to catch the error and display a meaningful message to the user.Following is my jquery ajax method code.

我在我的aspx页面上使用jquery ajax方法在后面的代码中调用web方法。如果调用失败,无论如何我想捕获错误并向用户显示有意义的消息。以下是我的jquery ajax方法码。

 $.ajax(
   {
   type:"POST",
   url:"Default.aspx/createitem",
   data:JSON.stringify({question : question, answer : ans, url : url, category : cat, maincat : maincat, validfrom : validfrom, validuntil :validuntil}),
   contentType:"application/json; charset=utf-8",
   dataType:"json",
   success:function(msg)
   {
   alert(msg.d);   
   //success code goes here
   },
   Error:function(xhr, status, error) {
      // Boil the ASP.NET AJAX error down to JSON.
  var err = eval("(" + xhr.responseText + ")");

  // Display the specific error raised by the server (e.g. not a
  //   valid value for Int32, or attempted to divide by zero).
  alert(err.Message);

      }

   }); 

But in case of any error like 'missing parameter' or something neither the success function nor the error function is getting executed an I had to check the response in firebug.Please could someone tell me what am I doing wrong?

但是如果出现任何错误,例如“缺少参数”或者某些事情,成功函数和错误函数都没有被执行,我必须检查firebug中的响应。请问有人能告诉我我做错了什么?

Thanks.

谢谢。

1 个解决方案

#1


0  

 Error:

should be

应该

error:

lowercase

小写

#1


0  

 Error:

should be

应该

error:

lowercase

小写