??yy 2015-01-19 21:13 采纳率: 0%
浏览 24

在Jquery变量中使用PHP

I'm trying to format what new comments look like on a Wordpress comment list, using Ajax. This is the snippet I'm working on.

The full piece can be found here: 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>');

}

The only one that works is "commenttext" because it doesn't have php. The others ("avatar" "author" and "timestamp") all come back with errors in Firebug.

I tried some suggestions I found, but couldn't get any to work. Any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • weixin_33739646 2015-01-19 21:17
    关注

    You should brace the string values with double quotes in Javascript.
    Like this:

    var author =  "<?php the_author_meta( 'user_url'); ?>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败