我在这里度过了漫长的一夜
web服务的结果是在json中。但是,返回的数据包含诊断数据。 我如何才获得结果集?
这是我的代码:
$(document).ready(function ()
{
$.ajax(
{
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://website.com",
data: data,
dataType: "json",
success: function (data)
{
alert('Total results found: ' + data.result.total);
$.each(data.result.records, function (value)
{
$("[id$='uxRegion']").append($("<option></option>").val(value.province).html(value.province));
});
}
error: function ajaxError(response)
{
alert(response.status + ' ' + response.statusText);
}
});
});
&#13;
这是有问题的json值
{
"value1": "etetetetete",
"value2": true,
"result": {
"records": [
{
"province": "Star world"
},
{
"province": "CNN"
}
],
"fields": [
{
"type": "text",
"id": "province"
}
],
"hash": "hash value"
}
}
&#13;
答案 0 :(得分:0)
您可以将data.result.records
设置为本地变量records
,如下所示:
success: function (data) {
var records = data.result.records;
alert('Total results found: ' + records.length);
$.each(records, function (value) {
$("[id$='uxRegion']").append($("<option></option>")
.val(value.province)
.html(value.province));
});
}
并且您在结果对象上没有total
属性,您应该使用.length
。