ajax 动态添加 option 选择框

ajax 动态添加 option 选择框

1、页面
<div class="form-group">
		<div class="col-sm-2 control-label"><label style="color:red;">&nbsp*</label>学校选择</div>
		<div class="col-sm-7">
		<select class="form-control" id="schooloption" v-model="dataInfo.schoolId">
		</select>
	    </div>
</div>
2、js
<script type="text/javascript">
	function schooloptionFun(){
		$.ajax({
			data:null,
			type:"POST",
			dataType:'json',
			async:true,//同步
			url:"/school/primaryList",
			success:function(data){
				if(data.rows==null){
					alert("数据为空!!!");
				}else{
					for (let i in data.rows) {
						let jsonObj =data.rows;
						let optionstring = "";
						for (var j = 0; j < jsonObj.length; j++) {
							optionstring += "";
							$("#schooloption").html(""+ optionstring);
						}
					}
				}
			}
		});
	}
	window.onload=schooloptionFun; //页面加载完自动加载
</script>

你可能感兴趣的:(ajax,okhttp,前端)