0
我知道,我的jQuery執行成功的操作,因爲我得到了服務器的身份驗證,但是訪問返回數據時遇到問題。我試着加入.d
到谷歌上找到的解決辦法..ASP.net,C#4,WebMethod,JQuery-Ajax,JSON數據 - 返回?
JQuery的:
$.ajax({
url: "something.asmx/Login",
type: "POST",
data: "{'a': '" + a.val() + "', 'p': '" + p.val() + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
cache: false,
timeout: 10000,
error: function() {
//Not needed here
},
success: function (msg) {
if (msg.d == '1') {
//Something not need for question
}
else {
//Not needed here neither.
}
}
});
而我的WebMethod(something.cs
):
private string res;
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Login(string a, string p) {
if (SecurityTools.GainAccess(a, p)) res = "1";
else res = "0";
return new JavaScriptSerializer().Serialize(res);
}
使用json串行器來創建您的`數據`字符串,而不是手動構建它。 – ThiefMaster 2010-11-23 18:24:55