【发布时间】:2015-11-13 01:54:26
【问题描述】:
我正在尝试解析从 asp.net 网络方法检索到的 JSON 结果。
[WebMethod]
public static string readCheckOutResult()
{
string uKey = DateTime.Now.ToString("yyyyMMddHHmmss");
string customerNo = HttpContext.Current.Session["customerNo"].ToString();
Core core = new Core();
DataTable dt = core.checkoutCustomerCart(customerNo, uKey); //dt = checked out product
string JSONResult = DataTableToJSON.DataTableToJsonObj(dt);
return JSONResult;
}
收到的 Json 结果如下所示。
[{"CustomerNo":"33157880","ProductNo":"ALDC125DC-DIXON","CustomerProductNo":"","ProductDescription":"32MM AL D/CAST CAM TYPE DC DIX ",
"UOM":" ","Price":"11.93200","Qty":"1","SubTotal":"11.93200","uKey":"201511131242","ModifyDate":"13/11/2015 12:42:25 PM","ID":"190"}]
$.ajax({
type: "POST",
url: "checkout.aspx/readCheckOutResult",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(codes) {
alert(codes.length);
var data = jQuery.parseJSON(codes.d);
for (var i = 0; i < data.d.length; i++) {
alert(data.d[i].CustomerNo);
}
alert(concatstring);
},
error: function() {
alert("Failed to Retrieve Data.");
}
});
我收到错误代码。长度未定义。我也试过codes.d.length但没有运气
【问题讨论】:
-
你为什么使用 async false?
标签: jquery asp.net json ajax asp.net-ajax