gpt4 book ai didi

javascript - 无法在 <script> 标签内回显 PHP 变量?

转载 作者:行者123 更新时间:2023-11-28 04:30:11 25 4
gpt4 key购买 nike

<分区>

这是我的 PHP 代码。我希望使用警报窗口显示错误。

 if ($projectid=="")
{
$error = 'You must choose a project.
Click &lsquo;back&rsquo; and try again.';
include error.html.php';
exit();
}

这是应该被浏览器解析的error.html.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Script Error</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">


</head>

<body>

<script>
var error = <?php echo $error ; ?>;
window.onload = function(){ alert(error); }
</script>
</body>
</html>

脚本标签怎么了?它们会阻止 PHP 运行吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com