0

我正在使用 jquery ajax 方法在单击“跨度”时调用 webmethod。这是 webmethod 在我的 aspx 页面之一中,我使用以下代码从母版页调用它。

 $(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);
              }
          });
       });
    });

当我单击跨度时,我可以看到 webmethod 被调用(通过调试),但即使在 webmethod 开始执行之前,我也会收到警报“错误”,并且我看到(一个空字符串) 消息被记录到 firebug 控制台中。据我所知,只有在 ajax 请求失败时才会执行“错误”函数。但我可以看到 webmethod 被执行。我不明白为什么错误函数仍在执行。

有人可以帮我解决这个问题。

谢谢

4

1 回答 1

1

error如果服务器端脚本返回不同于 200 的错误代码,则执行处理程序。您可以使用FireBug检查幕后究竟发生了什么。

于 2010-08-18T14:16:31.107 回答