jquery ajax 返回json 为什么给下拉列表赋不上值
<scripttype="text/javascript"charset="utf-8">functionloadState(){$.ajax({type:"POST",...
<script type="text/javascript" charset="utf-8">
function loadState() {
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8;",
url: "default.aspx/GetList",
data: "{code:'" + 130000000000 + "',areaLevel:'" + 1 + "'}",
dataType: "json",
success: function (results) {//返回 {"dt_area":[{"name":"北京","code":110000000000,"type":"PROVINCE","level":1,"area_Id":0,"areas_Id":""},{"name":"天津","code":120000000000,"type":"PROVINCE","level":1,"area_Id":7061,"areas_Id":""},{"name":"河北","code":130000000000,"type":"PROVINCE","level":1,"area_Id":12836,"areas_Id":""},{"name":"山西","code":140000000000,"type":"PROVINCE","level":1,"area_Id":67731,"areas_Id":""},{"name":"内蒙古","code":150000000000,"type":"PROVINCE","level":1,"area_Id":99468,"areas_Id":""},{"name":"辽宁","code":210000000000,"type":"PROVINCE","level":1,"area_Id":115330,"areas_Id":""},{"name":"吉林","code":220000000000,"type":"PROVINCE","level":1,"area_Id":133045,"areas_Id":""},{"name":"黑龙江","code":230000000000,"type":"PROVINCE","level":1,"area_Id":145774,"areas_Id":""},{"name":"上海","code":310000000000,"type":"PROVINCE","level":1,"area_Id":161859,"areas_Id":""}]}
var jsondata = JSON.parse(results.d);
var areadata = jsondata.dt_area;
getAreas(areadata);
},
error: function (results) {
alert("加载时出错,详情:" + results.responseText + ">>>" + results.statusText);
}
});
}
function getAreas(results) {
$. $.each(results, function (idx, item) {
var option = $("<option>").text(item.name).val(item.code);
ddlState.append(option);
});
}
$.fn.ready(function () {
loadState();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<select name="state" style="width:80px;" class="default" tabindex="3">
</select>
</form>
</body>
function getAreas(results) {
$. $.each(results, function (idx, item) {
var option = $("<option>").text(item.name).val(item.code);
ddlState.append(option);
});
}
多贴了一个 , select里面就是没有结果阿 展开
function loadState() {
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8;",
url: "default.aspx/GetList",
data: "{code:'" + 130000000000 + "',areaLevel:'" + 1 + "'}",
dataType: "json",
success: function (results) {//返回 {"dt_area":[{"name":"北京","code":110000000000,"type":"PROVINCE","level":1,"area_Id":0,"areas_Id":""},{"name":"天津","code":120000000000,"type":"PROVINCE","level":1,"area_Id":7061,"areas_Id":""},{"name":"河北","code":130000000000,"type":"PROVINCE","level":1,"area_Id":12836,"areas_Id":""},{"name":"山西","code":140000000000,"type":"PROVINCE","level":1,"area_Id":67731,"areas_Id":""},{"name":"内蒙古","code":150000000000,"type":"PROVINCE","level":1,"area_Id":99468,"areas_Id":""},{"name":"辽宁","code":210000000000,"type":"PROVINCE","level":1,"area_Id":115330,"areas_Id":""},{"name":"吉林","code":220000000000,"type":"PROVINCE","level":1,"area_Id":133045,"areas_Id":""},{"name":"黑龙江","code":230000000000,"type":"PROVINCE","level":1,"area_Id":145774,"areas_Id":""},{"name":"上海","code":310000000000,"type":"PROVINCE","level":1,"area_Id":161859,"areas_Id":""}]}
var jsondata = JSON.parse(results.d);
var areadata = jsondata.dt_area;
getAreas(areadata);
},
error: function (results) {
alert("加载时出错,详情:" + results.responseText + ">>>" + results.statusText);
}
});
}
function getAreas(results) {
$. $.each(results, function (idx, item) {
var option = $("<option>").text(item.name).val(item.code);
ddlState.append(option);
});
}
$.fn.ready(function () {
loadState();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<select name="state" style="width:80px;" class="default" tabindex="3">
</select>
</form>
</body>
function getAreas(results) {
$. $.each(results, function (idx, item) {
var option = $("<option>").text(item.name).val(item.code);
ddlState.append(option);
});
}
多贴了一个 , select里面就是没有结果阿 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询