The example in this article describes how jquery implements the method of updating the contents of a drop-down list when triggered. Share it with everyone for your reference, the details are as follows:
If the server has a request address to return the required data
url:/hello
Returns something like:
html:
Button:
Drop-down list:
js code:
$(function(){ $("#btn").click( $.ajax({ type:"POST", url:"http://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); } }); } }); ); });
I hope this article will be helpful to everyone in jQuery programming.