2015-01-19 3 views
-1

Ajax를 사용하여 Wordpress 코멘트 목록에 어떤 새로운 주석이 표시되는지 서식을 지정하려고합니다. 이것은 제가 작업중인 스 니펫입니다. Jquery 변수에서 PHP 사용하기

전체 조각

는 여기에서 찾을 수 있습니다 : 그것은 PHP가 없기 때문에 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"입니다. 다른 것들 ("아바타" "저자"와 "타임 스탬프")은 모두 파이어 버그에서 오류로 돌아온다.

내가 발견 한 몇 가지 제안을 시도했지만 작동하지 못했습니다. 어떤 도움을 주시면 감사하겠습니다.

+0

시도 견적을 미래를위한'' –

+0

을 : 그냥 브라우저에서 소스보기 실행 한 후 JS에서 문법이 엉망이되는지 확인한 다음 수정하십시오. – developerwjk

+0

이 파일이 PHP로 처리되고 있습니까? –

답변

0

누락 따옴표

이 시도 :

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>'); 

    } 
} 
+0

고마워요! 아주 간단한 수정. – BlueHelmet

0

자바 스크립트에서 문자열 값을 큰 따옴표로 묶어야합니다. 이처럼
다음 <?php ... ?> 태그 주위

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