【发布时间】:2011-05-18 20:31:05
【问题描述】:
所以我在一个应该调用 asp.net webservice 的页面上有以下功能,它似乎正在这样做,但页面上什么也没发生。下面是webservice下面的函数
$("#BlogSelectList li a").click(function () {
var str = ($(this).attr("href")).slice(1, 36)
$.ajax({
contentType: "application/json; charset=utf-8",
url: '../ws/WebServices.asmx/SetActiveBlog',
data: '{ActiveBlogID: "' + str + '"}',
dataType: 'json',
type: "post",
success: function (j) {
if (j.d == 1) {
window.location('http://www.msn.com');
}
else {
window.location('http://www.msn2.com');
}
alert('heyhi')
}, error: function (j) {
alert(':(')
}
});
});
这是 web 服务,我知道它正在执行,因为它正在运行一个存储过程,该过程使用“ssss”成功创建了一个日志条目,但是当单击锚点时页面实际上什么都不做,它不会重定向页面,它不会'不做任何警报,什么都不做。
[WebMethod(Description = "Sets the ActiveBlog.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool SetActiveBlog(string ActiveBlogID)
{
DbaseExecSpWithReturnValue Sproc = new DbaseExecSpWithReturnValue();
Sproc.SetSp("sp_CheckUsernameAvailable");
Sproc.AddParam(1);
Sproc.AddParam("Username", SqlDbType.Char, "ssss", 20);
int RetVal = Sproc.Execute();
Sproc.Close();
return true;
}
【问题讨论】:
-
您是否使用 Firebug 或类似工具检查过 Ajax 是否成功完成?
-
检查成功回调中的变量
j是否不为空或未定义。我想如果有 json 解析错误,它可能是可能的。它可以解释为什么您看不到任何警报,因为在您的 if 条件中检查j.d会使您的回调函数崩溃。
标签: jquery asp.net ajax web-services json