我在下面有一些 JSON 数据,我想div
使用 jQuery 创建一个 HTML,其中包含来自 AJAX JSON 响应的一些数据。将div
在成功代码中创建:
<script type="text/javascript">
$(document).ready(function() {
$("#add-notes-form").submit(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: '<?php the_permalink(); ?>',
dataType: 'json',
data: $("#add-notes-form").serialize(),
success: function(result){
$("#tab7 form").after("Code needs to go here");
}
});
});
});
</script>
JSON数据:
{"comment_ID":"2",
"comment_post_ID":"396",
"comment_author":"Me",
"comment_author_email":"me@gmail.com",
"comment_author_url":"http:\//gmail.com",
"comment_author_IP":"",
"comment_date":"2012-09-17 09:21:19",
"comment_date_gmt":"2012-09-17 16:21:19",
"comment_content":"This is a killer Note. 4",
"comment_karma":"0",
"comment_approved":"1",
"comment_agent":"",
"comment_type":"note",
"comment_parent":"0",
"user_id":"1"}
我正在尝试创建的 HTML:
<div id="comment-2" class="binder-user-note">
<a href="?delete=2" id="close-note"></a>
<h1>I added this on: Monday 17th September 2012</h1>
<p>This is a killer Note. 2</p>
<a href="edit?2" id="editnote"></a>
</div>
到目前为止我所拥有的:
<div id="comment-'+response.comment_ID+'" class="binder-user-note">
<a href="?delete='+response.comment_ID+'" id="close-note"></a>
<h1>I added this on: '+response.comment_date+'</h1>
<p>'+response.comment_content+'</p>
<a href="edit?'+response.comment_ID+'" id="editnote"></a>
</div>
response
是对象。