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