0
行,所以这是推动我疯了.. 我试图从一个Web方法解析JSON为<ul>
,这里是我得到了什么:jQuery的解析JSON阵列
function searchPostcode() {
var search = $("#txtPostcode").attr("value");
//alert(search);
$.ajax({
type: "POST",
url: "DeliverySettings.aspx/getDeliveryInfoForPostcode",
contentType: "application/json; charset=utf-8",
data: "{'postcode':'" + search + "'}",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded(result) {
var items = [];
$.each(eval(result), function (key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('jsonresults');
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
}
这里是一个示例在JSON从返回的WebMethod:
[{"Name":"Full Pallet","Price":"90.0000"},{"Name":"Half Pallet","Price":"60.0000"},{"Name":"Quarter Pallet","Price":"40.0000"},{"Name":"Small Parcel","Price":"30.0000"},{"Name":"Medium Parcel","Price":"20.0000"},{"Name":"Large Parcel","Price":"10.0000"}]
我一直有和没有eval
无济于事试过,我只是不能进入名单...请帮助! :)
我的坏,我较早前测试,并命名为标签,而不是设置一个class和id –
Leigh
干杯的抬起头的ID,这是排序。 val.Name给我未定义..? – Leigh
@Leigh:你确认你的回复是否正确到达? 'console.log(result)' – user113716