2010-11-23 41 views
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); 
} 
+0

使用json串行器来创建您的`数据`字符串,而不是手动构建它。 – ThiefMaster 2010-11-23 18:24:55

回答

0

我发现我的回答,我不得不写:

if (msg.d == '"1"') 

都与JavascriptSerializerNewtonstof.Json命名空间。