如何从java脚本模板传递php参数


How to pass php parameter from java-script template

>我在下面有一个代码,它通过从上传这些图像的文件夹中读取图像名称在UI上显示图像名称,

这些图像名称是使用 java 脚本模板显示的,我想将该名称传递给 php 函数,以便通过按图像名称点击 db 来检查其状态。

以下是图像名称在 UI 中的显示方式:

<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
           <span>{%=file.name%}</span>
              <!----- new update -------->
                  var a= file.name;
                     $.ajax({
                        type: "POST",
                        url: "http://localhost/tripvioapp/trips/showStatus/",
                        dataType: "text",
                        data: {image_name: a,trip_id: '2'},
                        success: function(msg){ 
                              alert(msg);//how can i display this value in this place
                       }
                     });
        </td>
    </tr>
{% } %}
</script>

基本上,我已经将文件上传与Codeigniter(php框架)从本教程中集成

在一起

到目前为止我尝试过什么

我尝试通过{%=file.name%}如下所示

$this->tripmodel->getImageStatusByUidName(''"{%=file.title%}'"',"2"); //calling php function

结果:不是从{%=file.name%}传递值,而是按原样传递。

预期(因为它应该像这样在内部工作:)

$this->tripmodel->getImageStatusByUidName("imageName.jpg","2");

谁能帮我解决这个问题,请?

你应该把php代码放在两者之间类似的东西

    <?php
    $this->tripmodel->getImageStatusByUidName( "{%=file.name%}","2");
    ?>

玩弄它。我还没有测试过