服务端假如有个请求地址用来返回所需数据
url:/hello
返回类似
[{"西瓜":10},{"苹果":12},{"香蕉":13},{"芒果":14}]
这样的json数据
html:
按钮<input type="button" id="btn" value="按 钮" />
下拉列表<select id="sel"></select>
js:
$(function(){
$("#btn").click(
$.ajax({
type:"POST",
url:"https://localhost/XXXX/Test",
cache: false,//不缓存
dataType:"json",//返回数据格式
success:function(ret){
$("#sel").empty();
$.each(ret,function(ind){
for(var key in ret[ind]){
var opt = $("<option></option>");
opt.val(ret[ind][key]);
opt.text(key);
$("#sel").append(opt);
}
});
}
});
);
});服务端假如有个请求地址用来返回所需数据
url:/hello
返回类似