views:

24

answers:

1

hi, 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.

 $.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?

Thanks.

A: 
 Error:

should be

error:

lowercase

jAndy
thank you so much.such a silly mistake..
kranthi
just for testing purpose I've changed the webmethod(which doesnt exist) name in $.ajax 'url' parameter,then it did not execute the error/success function.Could u tell me the reason please?
kranthi