日期:2014-05-16  浏览次数:20968 次

Jquery ajax 取返回值 json的问题
前台代码
function ajax(Qt, PID) {
            $.ajax({
                url: "../Carts.asmx/CartsQuantity",
                type: "POST",
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
                data: "{ Quantity:" + Qt + ", ProductID:" + PID + "}",
                error: function () { alert("错误"); },
                success: function (result) {
                    //var data = eval('(' + result + ')');
                    alert(result.d);//显示{"UserID":"4","Quantity":"11","ProductID":"5943"}
                    alert(result.Quantity);//显示undefined
                }
            });
        }
用eval方法也不行,请问怎么去到KEY的值呢?


后台代码
[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    [System.Web.Script.Services.ScriptService]
    public class Carts : System.Web.Services.WebService
    {
        [WebMethod]
        public string CartsQuantity(int Quantity, int ProductID)
        {
            string UserID = BLL.MyCookies.Cookie.GetCookie("UserID").ToString();
            StringBuilder sb = new StringBuilder();
            sb.Append("{");
            sb.Append("\"UserID\":\"" + UserID + "\",");
            sb.Append("\"Quantity\":\"" + Quantity + "\",");
            sb.Append("\"ProductID\":\"" + ProductID + "\"");
            sb.Append("}");