如何通过HTML输入标签调用PHP函数(Yii1.1)

uqjltbpv  于 2022-11-09  发布在  PHP
关注(0)|答案(1)|浏览(153)

正如在标题中看到的,我正在寻找一个解决上述问题的方法。我有以下按钮:
<input onclick="setRefreshTimer();" type="button" value="10 Seconds">
在函数的下面。这个函数为刷新计时器设置了一个特定的时间(在这个例子中是10秒),这样默认值30秒就会被覆盖。

function setRefreshTimer() {
  Yii::log("I am not certain if I was here!");
  CHtml::refresh(Yii::app()->config->set('DASHBOARD_RELOAD', 10));
  return CHtml::refresh(Yii::app()->config->get('DASHBOARD_RELOAD'), $url);
}

我现在需要的是一个解决方案,如何调用函数时,按钮被点击。上面的代码是我已经尝试过,但它似乎不能正常工作,我似乎找不到原因。
欢迎您提供任何关于如何解决/改进此问题的帮助、建议和/或提示。

mbyulnm0

mbyulnm01#

好的,伙计们。非常感谢你们给我的精彩链接。很抱歉我缺席了这么长时间。但是多亏了你们,我成功地用 AJAX 打了电话,而且工作得很好。这就是我是怎么做到的。
首先,DashboardController.php中的函数将 Jmeter 板的刷新计时器更改为10秒。

public function actionSetRefreshTimer() {
    $url = Yii::app()->request->url;

    Yii::log("I am not certain if I was here!");
    if (isset($_GET['DASHBOARD_RELOAD']) !== 10) {
      Yii::log("And it went into the if!");
      CHtml::refresh(Yii::app()->config->set('DASHBOARD_RELOAD', 10));
    }

现在, AJAX 调用完成了这项工作。

<button id="tenSeconds">10 Seconds</button>

  <script>
$("#tenSeconds").click(function() { 
  console.log("The click worked just fine");
  $.ajax({
    url: '/path/to/my/function/SetRefreshTimer',
    method: 'POST',
  }); 
});
</script>

相关问题