dongsi7067 2018-10-24 06:28
浏览 125

如何在javascript函数中使用“get_template_directory_uri”

This is a part of my WordPress PHP file code, in this I wrote a JavaScript code and I would like to display the names, images from the query. Names are displayed but images are not displaying, then I added get_template_directory_uri(), after adding get_template_directory_uri() it is showing error in console like this "Uncaught Syntax Error: missing ) after argument list". All images are stored in WordPress theme image folder. How to write javascript code to display images? Please Help me out from this problem.

Thanks.

function partyFunction(){
debugger;
$postdata = {};
$postdata["partyId"]=$("#partydropdown").val();
$.post('<?php echo get_template_directory_uri() ? 
>/GetPartiesData.php',$postdata,function (data) {
debugger;
console.log(data);
var stringreplace = data.replace(/['"]+/g, '');
console.log(stringreplace);
var res = stringreplace.split(",");
  console.log(res);
  $("#partyBody").empty();
  $("#partyBody").html('');
  $("#partyBody").append("<tr>"+
    "<td>"+res[1]+"</td>"+
    "<td><img src='"+<?php echo get_template_directory_uri() ? 
 >/img/++res[2]+"' style='padding:5px;vertical-align: middle;border-style: 
 none;width:129px;height:109px;' ></td>"+
 "<td><img src='"+res[3]+"' style='padding:5px;vertical-align: 
 middle;border-style: none;width:129px;height:109px;' ></td>"+
 "<td><a href='"+res[4]+"' target='_blank'>click here</a></td>"+
 "</tr>");
 });
 }
  • 写回答

3条回答 默认 最新

  • du22399 2018-10-24 06:30
    关注

    Uncaught SyntaxError: missing )

    <img src='"+<?php echo get_template_directory_uri() ?>/img/++res[2]+"'
    

    Replace with:

    <img src='<?=get_template_directory_uri()?>/img/"+res[2]+"'
    

    You missed semicolon the end of statement:

    <?php echo get_template_directory_uri(); ?>
    -                                      ^ just missed 
    

    P.S. you have used same line more than once, kindly ensure all lines have been modified.

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算