我正在尝试使用Ajax格式化Wordpress注释列表上的新注释。这是我正在研究的代码段。
完整的文章可以在这里找到:http : //pastebin.com/UHnPgf4J
success: function(data, textStatus){
if(data=="success"){
var avatar = <?php echo get_avatar( $comment, 32 ); ?>;
var author = <?php the_author_meta( 'user_url'); ?>;
var timestamp = <?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?>;
var commenttext = jQuery('#comment').val();
jQuery('<li>'+'<div class="comment-author vcard">'+avatar+
'<div class="comment-meta">'+author+'</div>'+
'<div class="comment-time-stamp">'+timestamp+'</div>'+
'<div class="comment-text">'+commenttext+'</div>'+'</li>'+).insertBefore(respond);
statusdiv.html('<p class="ajax-success" >Thanks for your comment. We appreciate your response.</p>');
}
唯一有效的是“ commenttext”,因为它没有php。其他(“头像”,“作者”和“时间戳”)在Firebug中均返回错误。
我尝试了一些发现的建议,但无济于事。任何帮助,将不胜感激。
<?php ... ?>
标签周围缺少引号
试试这个:
success: function(data, textStatus){
if(data=="success"){
var avatar = "<?php echo get_avatar( $comment, 32 ); ?>";
var author = "<?php the_author_meta( 'user_url'); ?>";
var timestamp = "<?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?>";
var commenttext = jQuery('#comment').val();
jQuery('<li>'+'<div class="comment-author vcard">'+avatar+
'<div class="comment-meta">'+author+'</div>'+
'<div class="comment-time-stamp">'+timestamp+'</div>'+
'<div class="comment-text">'+commenttext+'</div>'+'</li>'+).insertBefore(respond);
statusdiv.html('<p class="ajax-success" >Thanks for your comment. We appreciate your response.</p>');
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句