【发布时间】:2016-11-10 06:19:02
【问题描述】:
这是我的 PHP 代码。我希望使用警告窗口显示错误。
if ($projectid=="")
{
$error = 'You must choose a project.
Click ‘back’ 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 运行吗?
【问题讨论】:
-
警报显示什么?
-
javascript在客户端执行,php在服务器端和nary twain会见...
-
@Katie lol - 如果 Javascript 是内联 HTML 而不是在 JS 文件中,那么您可以在其中使用尽可能多的 PHP。
-
` `
-
@Katie 我希望人们也不要尝试将两者混合,但 PHP 可以回显客户端执行的 javascript...
标签: javascript php html json