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 직렬기를 사용하여'data' 문자열을 만듭니다. – ThiefMaster
서버로부터 무엇이 되돌아 왔는지 확인하려면 콜백에'console.log (msg);'를 추가 한 다음 Firebug가 열려있는 동안 함수를 실행하십시오. – ThiefMaster