在Jquery变量中使用PHP
我正在尝试使用Ajax格式化Wordpress评论列表中的新评论。这是我正在编写的代码片段 全文可在此处找到:在Jquery变量中使用PHP,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我正在尝试使用Ajax格式化Wordpress评论列表中的新评论。这是我正在编写的代码片段 全文可在此处找到: success:函数(数据、文本状态){ 如果(数据=“成功”){ 变量avatar=; var author=; var时间戳=; var commenttext=jQuery('#comment').val(); jQuery(''+''+avatar+ ''+作者+''+ ''+时间戳+''+ ''+commenttext+'+''+)。在之前插入(响应); html(“感谢您的
success:函数(数据、文本状态){
如果(数据=“成功”){
变量avatar=;
var author=;
var时间戳=;
var commenttext=jQuery('#comment').val();
jQuery(''+''+avatar+
''+作者+''+
''+时间戳+''+
''+commenttext+'+' '+)。在之前插入(响应);
html(“感谢您的评论。我们感谢您的回复。
”;
}
唯一有效的是“commenttext”,因为它没有php。其他(“avatar”、“作者”和“时间戳”)都在Firebug中出现错误
我尝试了一些我找到的建议,但没有任何效果。如果有任何帮助,我将不胜感激。您应该在Javascript中用双引号括住字符串值。
像这样:
var author = "<?php the_author_meta( 'user_url'); ?>";
var author=”“;
标记周围缺少引号
试试这个:
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>');
}
}
success:函数(数据、文本状态){
如果(数据=“成功”){
var avatar=“”;
var author=“”;
var timestamp=“”;
var commenttext=jQuery('#comment').val();
jQuery(''+''+avatar+
''+作者+''+
''+时间戳+''+
''+commenttext+'+' '+)。在之前插入(响应);
html(“感谢您的评论。我们感谢您的回复。
”;
}
}
尝试引用未来的
:运行此功能后,只需在浏览器中查看源代码,查看JS中的语法是如何混乱的,然后进行修复。此文件是否由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>');
}
}