views:

38

answers:

1

hi, I am using jquery ajax method to invoke a webmethod upon clicking a 'span'.This is webmethod is in one of my aspx pages and I am invoking it from the master page using the following code.

 $(document).ready(function(){
     $("#btn").click(function() {
        $.ajax({   
              type: "POST", 
              url: "Default.aspx/removedata",
              data:"{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",  
              success:function(msg) {  
                   $("li#search").removeClass('current');
                   $("li#search").addClass('hide');
                   $("#tabnew").addClass('hide');
                   window.location="Result.aspx";       
              },
              error:function(xhr, status, error) {
                  alert("error");                       
                  //var err = eval("(" + xhr.responseText + ")");
                  // Display the specific error raised by the server 
                  //alert(err.Message);
                  console.log(xhr.statusText);
              }
          });
       });
    });

when I click the span I can see the webmethod getting invoked(by debugging ),but even before the webmethod starts executing I get the alert 'error' and I see (an empty string) message being logged into the firebug console. As far as I know the 'error' function gets executed only if the ajax request fails.But I can see the webmethod getting executed.I do not understand why the error function is executing even then.

Could someone please help me with this.

Thanks

+1  A: 

The error handler is executed if the server side script returns an error code different than 200. You could use FireBug to inspect what exactly is happening under the covers.

Darin Dimitrov
Fiddler2 (http://www.fiddler2.com/) is also a very helpful tool for knowing precisely what is in the HttpResponse returned from the webservice.
mikemanne