0
私のjQueryは、サーバーで認証されているため、成功したアクションを実行しますが、戻りデータへのアクセスに問題があります。私が試した追加Googleで見つかったソリューションへ.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シリアライザを使用して、手動で構築するのではなく、 'data'文字列を作成します。 – ThiefMaster
サーバから何が返ってくるか調べるには、コールバックに 'console.log(msg);'を追加し、Firebugが開いている間に関数を実行してください。 – ThiefMaster