所以我有一個頁面上應該調用一個asp.net web服務的以下功能,它似乎這樣做,但沒有發生在頁面上。下面是低於該函數的WebServicejquery Ajax沒有響應?
$("#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;
}
你檢查使用螢火蟲或類似的東西,看看阿賈克斯成功完成? – 2011-05-18 20:32:45
檢查成功回調中的變量「j」是否爲空或未定義。我想這可能是有可能的,如果有一個JSON解析錯誤。這將解釋爲什麼你沒有看到任何警報,因爲在你的if條件中檢查'j.d'會導致你的回調函數崩潰。 – DarthJDG 2011-05-18 20:40:02