简体   繁体   中英

How to pass php parameter from java-script template

I have a code below, which display image name on UI by reading it from the folder where those images are uploaded,

These image names are displaying using a java-script template , I want to pass that name to a php function in order to check its status by hitting the db by the image name..

Here is how the image name is displaying in 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>

Basically, i have integrated file upload with Codeigniter(php framework) From this tutorial


What i tried so far

i tried passing {%=file.name%} as below

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

Result: instead of passing value from {%=file.name%} , its passing as it is.

Expected (as it should work internally like this:)

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

Can anyone help me with this,please?

you should put php code betwee somthing like

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

play around with it. i have not tested it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM