php - 如何在点击 php 时强制刷新?
问题描述
我在 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>
我无法真正弄清楚我的问题,是我在函数中生成的变量没有正确传递,还是还有其他问题?
解决方案
用 JavaScript 很容易制作,
function myFunction() {
window.location.reload();
}
然后你只需将功能添加到你的按钮,
<button class="myButton" onclick=myFunction()">Click to reload</button>
推荐阅读
- docker - 从 docker 容器提交时,Spark 作业未安排给工作人员
- csvhelper - 使用 CsvHelper 将不同的列标题名称映射到 C# 实体类中的单个字段
- reactjs - react dropzone,限制上传的图片数量,超过限制时给出错误消息
- amazon-web-services - 如何监控和调试 AWS 中对 s3 的每个请求?
- actions-on-google - 已部署但未调用 Google 操作
- java - 通过 LAN 建立 Java 网络
- react-native - 如何将json字符串从react-native中的fetch转换为对象
- python-3.x - 我可以使用 Tornado 将 json-rpc 解析为 Web 前端吗?
- javascript - fullCalendar v5 eventOverlap 资源
- api - 无法从端点参数中读取数据,只能读取 TokenType 和 ValueKind