我正在尝试以一行的自举形式显示从php加载的json数据 但不和我合作
这里是JAVASCRIPT
var req_='getprosp&id='+trdata.IDP;
$.ajax({
type: "GET",
url: "lib/read.php?req="+req_,
contentType: "application/json; charset=utf-8",
global: false,
async: true,
dataType: "json",
success: function(data) {
for (var i in data) {
$('input[name="'+i+'"]').val(data[i]);
}
//$.each(data, function(key, val) {console.log(val) });
}
});
感谢您的帮助
答案 0 :(得分:0)
样本表格
<div class="x_content" id="editForm" >
<form role="form" id="prosp" action="" method="post" >
<div id="myTabContent" class="tab-content">
<div role="tabpanel" class="tab-pane fade active in" id="tab_content1" aria-labelledby="home-tab">
<!-- Text input-->
<div class="form-group">
<label class="col-md-1 control-label" for="NOM_">Nom</label>
<div class="col-md-4">
<input id="NOM_" name="NOM_" type="text" placeholder="" class="form-control input-md" required="" data-bind="value: selected.NOM_" value="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-1 control-label" for="PRENOM_">Prénom</label>
<div class="col-md-4">
<input id="PRENOM_" name="PRENOM_" type="text" placeholder="" class="form-control input-md" required="" value="">
</div>
</div>
<!-- nature-->
<div class="form-group">
<label class="col-md-1 control-label" for="NATURE_">Nature</label>
<div class="col-md-4">
<select id="NATURE_" name="NATURE_" class="form-control">
<option value=""></option>
<option value="1">Publique</option>
<option value="2">Privé</option>
</select>
</div>
</div>
</div>
<br/>
<button id="valider" type="submit" class=" btn btn-success" style="float: right">Valider</button>
</form>
</div>
的console.log
对象{PK_:“15865”,NOM_:“EZZAR”,PRENOM_:“TAOUFIK”,CIBLAGE_:“A”,NATURE_:“Publique”......}
答案 1 :(得分:0)
与此合作:
var req_='getprosp&id='+trdata.IDP;
$.ajax({
type: "GET",
url: "lib/read.php?req="+req_,
contentType: "application/json; charset=utf-8",
global: false,
async: true,
dataType: "json",
success: function(data) {
$.each(data, function(key, val) {
//console.log(val)
var namef;
for(namef in val){
console.log(namef + " = " + val[namef]);
$('input[name="'+namef+'"]').val(val[namef]);
}
});
}
});