<select>
</select>
$(document).ready(function () { //此處頁面開啟即請求api
$.ajax({
type:"GET",
url:"{:url("Room/houseData")}",
contentType: "application/json; charset=utf-8",
async : true ,
dataType: "json",
success: function (date) {
var optionstring = "";
for (var j = 0; j < date.length;j++) {
console.log(date[j].house_name);
console.log(date[j].id);
optionstring += "<option value=\"" + date[j].id + "\" >" +date[j].house_name+" " + "</option>";
$("#select").html("<option value="0">請選擇...</option> "+optionstring);
}
},
error: function (msg) {
layer.msg("資料出錯了!!");
});
<select>
</select>
$(document).ready(function () { //此處頁面開啟即請求api
$.ajax({
type:"GET",
url:"{:url("Room/houseData")}",
contentType: "application/json; charset=utf-8",
async : true ,
dataType: "json",
success: function (date) {
var optionstring = "";
for (var j = 0; j < date.length;j++) {
console.log(date[j].house_name);
console.log(date[j].id);
optionstring += "<option value=\"" + date[j].id + "\" >" +date[j].house_name+" " + "</option>";
$("#select").html("<option value="0">請選擇...</option> "+optionstring);
}
},
error: function (msg) {
layer.msg("資料出錯了!!");
}
});
});