weixin_33726313 2017-05-26 12:43 采纳率: 0%
浏览 82

在TPL中运行PHP

I am trying to modify a module TPL file and face some difficulties.

I have a dropdown list and want to run an SQL query when the user selects an item from the list. So far I have tried to run a PHP file through Ajax in order to run the query but without any success. I have seen various examples but can't understand how it should be done. Nevertheless here is what I have done so far.

This is the code I use on the TPL file:

<select id="statusSelect" onChange="updateStatus({$order.id_order|escape:'html':'UTF-8'})">
<option value="1"> test1 </option>
<option value="2"> test2 </option>
<option value="3"> test3 </option>
</select>

This is the JS function I use to call the PHP file, through Ajax:

<script type="text/javascript">
    function updateStatus(order_id_sent)
    {   
    //TEST
    //alert(document.getElementsByTagName("option")[selectedIndex].value + " " + order_id_sent);    
    $.ajax({
    url: 'setStatus.php', 
    type: 'get',
    data: 'ajax=true',
    success: function()
    {
    alert("It worked");
    }
    });
    }
    </script>

And here is my setStatus.php file which I want to call:

<?php
include_once('../../../../../config/config.inc.php');
include_once('../../../../../init.php');
public function doStuff()
{
echo "alert('test');"; 
return 1;
}
if ($_GET['ajax'])
{
echo function doStuff();
}
?>
  • 写回答

2条回答 默认 最新

  • weixin_33690367 2017-05-26 12:51
    关注

    use

    $( document ).ready(function() {
      $("#statusSelect").change(function(){
          statusUpdate($(this).val());
      });
    }
    

    in your code the name of the function is statusUpdate and in the select you call updateStatus

    i wish this can help you

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料