我想从第二页开始提醒第一页,例如我有以下页面
<?php
$sql = "SELECT table_id, on, off FROM tables"; //just fetching and filling my table with the info
$stmt = mysqli_prepare($dbc, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $table_id, $on, $off);
while(mysqli_stmt_fetch($stmt)){
?>
<tr>
<td><?php echo '<button onclick="ShutTime('.$table_id.')" >Disable</button>'; ?><input type="hidden" id="off_<?php echo $table_id; ?>" value="<?php echo $off; ?>"></td> //this button belongs to the code below
</tr>
}
function ShutTime(table_id, off) { //these datas are sent to another script
var off = $("#off_" + table_id).val();
alertify.confirm("Are you sure to disable this ?",
function(){
$.post("ajax/deactivateTime.php", { //here
table_id: table_id,
off: off,
},
function (data, status) {
location.reload();
}
);
}
我在这里处理它们
<?php
//This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id']) AND isset($_POST['off']))
{
$table_id = (int) ($_POST['table_id']);
$off = (int) ($_POST['off']);
$sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
$r = mysqli_query($dbc, $sql);
//after execution I want to alert the above datas into the first script
$res="Data Passed Successfully"; //as a Test I tried to do like this but no success
echo json_encode($res);
}
else
{
exit();
}
一切正常,我想要的只是将 deactivateTime.php 中的数据提醒到我的索引页面,我怎样才能实现这一点?
最佳答案
我解决了我的问题
function ShutTime(table_id, off) { //these datas are sent to another script
var off = $("#off_" + table_id).val();
alertify.confirm("Are you sure to disable this ?",
function(){
$.post("ajax/deactivateTime.php", { //here
table_id: table_id,
off: off,
},
function (data, status) {
alert(data); //just alerting the data
location.reload();
}
);
}
<?php
//This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id']) AND isset($_POST['off']))
{
$table_id = (int) ($_POST['table_id']);
$off = (int) ($_POST['off']);
$sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
$r = mysqli_query($dbc, $sql);
$res="Data Passed Successfully"; // and junt echoing it as usual
}
else
{
exit();
}
关于javascript - php ajax mysql从另一个文件发出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678889/