即使调用webmethod的请求成功,为什么$ .ajax的'error'函数仍然执行?
问题描述:
我正在使用jquery ajax方法来调用一个webmethod在单击'span'时。这是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开始执行我得到的警报“错误”,我看(空字符串)消息被登录到萤火虫控制台。 据我所知只有在ajax请求失败时才会执行'error'函数。但是我可以看到webmethod得到执行。我不明白为什么错误函数正在执行。
有人可以帮助我这个。
感谢
你做任何网址重写? – Aristos 2010-08-18 14:21:34
不,我没有进行url rewrite.actually我只是删除存储在我调用的webmethods的会话中的一些数据。 – kranthi 2010-08-18 14:27:35
返回的状态是什么? – 2010-08-18 14:34:22