0
我有下面的JSON数据,基本上我想要做的是用数组中包含的相关HTML填充几个div。尽管JSON数据循环来填充HTML
[{"id":"1","name":"profile title","html":"<h2 class=\"entry-title\" id=\"title\">Settings, Put something here?<\/h2>","typeId":"1"},
{"id":"2","name":"username","html":"<fieldset disabled><br><label for=\"nameinput\">Username<\/label><input type=\"text\" class=\"form-control\" placeholder=\"'.$name.'\" ><\/fieldset><p>","typeId":"1"},
{"id":"3","name":"date of birth","html":"<label for=\"dob\">Date of birth<\/label><input type=\"text\" name=\"dob\" class=\"form-control\" placeholder=\"01\/02\/2000\"><p>","typeId":"1"}]
这里是JS:
$(document).ready(function(){
$("#profile").one("click",function(){
$.ajax({
type: "GET",
url: ROOT+"controlpanel/profile",
dataType:"json",
success: function(data){
$.each(data, function(id, data1)
{
$('#title').html(data1.html);
$('#container').append(data1.html);
});
}
});
});
});
我的问题是,我想在ID为1的HTML在不同的div去ID 2.
数组中的每个元素都应该转到不同的div上吗? – milagvoniduak