少し問題があります-これをやろうとしています:
$('#content').append('<div class="square"><h2>'+item.name+'</h2><h3>'+item.comment+'</h3></div>');
そして、次のようなコンテンツを表示しています:
...しかし、次のようなコンテンツを表示したい:
...これは、追加から JavaScript 変数を削除し、それを古いテキストだけに置き換えると実行されます。
誰が何が起こっているのか知っていますか?
必要に応じて、コードの完全なバージョンを次に示します。
$.ajax({
url: 'yourcurations.php',
data: '',
dataType: 'json',
success: function(data){
$.each(data, function(i, item) {
$('#content').append('<div class="square"><h2>'+item.name+'</h2><h3>'+item.comment+'</h3></div>');
})
}
});
CSS
.square {
width: 150px;
height: 150px;
margin-right:50px;
margin-bottom: 50px;
display: inline-block;
border: 1px solid gray;
}
h2 {
margin-top: 0;
font-size: 1.5em;
color: black;
}
h3 {
font-size: 1em;
margin-top: -15px;
color: gray;
}
HTML
どうもありがとう