任何人都知道如何在php中调用goBack()
?
它一直告诉我:
致命错误:调用未定义的函数goBack()
我不知道为什么......
这是我的PHP代码:
<?php
include "config.php";
include "session_user.php";
?>
<script>
function goBack(){
alert();
window.history.go(-1);
}
</script>
<?php
if(isset($_GET['d'])):
$stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
$stmt->bind_param('s', $id);
$id = $_GET['d'];
if($stmt->execute()):
goBack();
else:
echo "<script>alert('".$stmt->error."')</script>";
endif;
endif;
?>
有什么建议吗?
答案 0 :(得分:1)
如果你想从php调用javascript函数。它有很多方法
将您的代码更改为以下内容,
方法1
<?php
include "config.php";
include "session_user.php";
?>
<script>
function goBack(){
alert();
window.history.go(-1);
}
</script>
<?php
if(isset($_GET['d'])):
$stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
$stmt->bind_param('s', $id);
$id = $_GET['d'];
if($stmt->execute()):
echo "<script>goBack();</script>";
else:
echo "<script>alert('".$stmt->error."')</script>";
endif;
endif;
?>
方法2
<?php
include "config.php";
include "session_user.php";
if(isset($_GET['d'])):
$stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
$stmt->bind_param('s', $id);
$id = $_GET['d'];
if($stmt->execute()):
echo "<script>histort.back()</script>";
else:
echo "<script>alert('".$stmt->error."')</script>";
endif;
endif;
?>