[英]php ajax mysql alerting from another file
I want alert the first page from the second one, for example I have the below page 我要提醒第二个页面的第一页,例如我有以下页面
<?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();
}
);
}
Here I processing them 我在这里处理它们
<?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();
}
Everything is working fine, all I want is to alert the datas from deactivateTime.php to my index page, how can i achieve that? 一切工作正常,我想要提醒的是deactivateTime.php中的数据到我的索引页,我该如何实现?
I resolved my problem doing like 我这样解决了我的问题
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.