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.