【问题标题】:How do I force a refresh on click on php?如何在点击 php 时强制刷新?
【发布时间】:2019-04-11 14:58:50
【问题描述】:

我在 html 中有两个按钮,分别是返回和下一步。 如果我单击这些按钮,变量会增加或减少。 这个变量被发送到一个有 sql 语句的 function.php。 声明是:

select * from x where dimension is = value

如何刷新页面以在查询中显示我的新表?

这是我的 php:

    function tbl_showPage($page){


    global $mysqlhost, $mysqluser, $mysqlpwd, $mysqldb;


    $connection=mysqli_connect($mysqlhost, $mysqluser, $mysqlpwd) or die ("Verbindungsversuch fehlgeschlagen");
    mysqli_select_db($connection, $mysqldb) or die("Konnte die Datenbank nicht waehlen.");


    if($page<1)
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension='1'";
    }
    elseif($page>9)
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension='9'";
    }
    else
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension=$page";
    }
    $quest_query = mysqli_query($connection, $sql_tbl_questions) or die("Anfrage nicht erfolgreich");
    $i = 0;

    while ($question = mysqli_fetch_array($quest_query)) {
        $i++;
        echo '<tr>';
        echo '<th>'.$i.'</th>';
        echo '<th>'.$question['question'].'</th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="0" required></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="2.5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="7.5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="10"></th>';
        echo '</tr>';
        $dimensions = $question['dimension'];
    }
    echo '<tr>';
        echo '<th></th>';
        echo '<th>Kommentar/Ihre Anmerkung</th>';
        echo '<th class="text-center" colspan=5><textarea rows=3 cols=50 name="Kommentar"></textarea></th>';
        echo '</tr>';



    echo '<input type="hidden" name="gesamt" value="'.$i.'">';
    echo '<input type="hidden" name="dimensions" value="'.$dimensions.'">';
    echo '<input type="hidden" name="size" value="'.$_POST['size'].'">';    
    echo '<input type="hidden" name="branche" value="'.$_POST['branche'].'">';




}

也许我的 var 没有通过?

javascript 函数是这样的:

<script type="text/javascript">


var ki = kd = 1;
function increase()
{
    
	ki++;
	

	 $.ajax({
      type: "POST",
      url: 'inc/functions.php',
      data: ({page:ki}),
      success: function(data){
         console.log(data);
      }
    });
	window.location.reload();
	
}

function decrease()
{
	kd--;

	 $.ajax({
      type: "POST",
      url: 'inc/functions.php',
      data: ({page:kd}),
      success: function(data){
         console.log(data);
      }
    });
	window.location.reload();
	
	
}


</script>

我无法真正弄清楚我的问题,是我在函数中生成的变量没有正确传递,还是还有其他问题?

【问题讨论】:

标签: php html ajax jss


【解决方案1】:

好像你在这里混合 PHP 和 javascript。

您的按钮上有 onClick 功能吗?如果你这样做了,并且调用了一个 javascript 函数,你可以添加 window.location.reload();在您的 javascript 函数底部重新加载页面。

提示:在帖子中使用编辑功能并添加与您的问题相关的代码,这样更容易获得帮助。

【讨论】:

    【解决方案2】:

    用 JavaScript 很容易制作,

    function myFunction() {
        window.location.reload();
    }
    

    然后您只需将功能添加到您的按钮,

    <button class="myButton" onclick=myFunction()">Click to reload</button>
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多