本文介绍了PHP回应的Javascript不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过php动态回应javascript有一点问题。这是我的代码
I am having a little issue with echoing javascript dynamically via php. Here is my code
$url = "http://www.newsite.com";
echo "
<html>
<head>
<title>Redirecting</title>
</head>
<body onload='redirect()'>
Not Logged In
<script type = 'text/javascript'>
function redirect() {
window.location=".$url."
}
</script>
</body>
</html>
";
我的javascript控制台告诉我找不到redirect()(Uncaught ReferenceError:redirect is未定义)
My javascript console is telling me that "redirect()" cant be found (Uncaught ReferenceError: redirect is not defined)
任何想法导致了什么?
推荐答案
你'错过引号。这将解决您的问题:
You're missing a quotation mark. This will fix your issue:
function redirect() {
window.location='".$url."';
}
目前,您的页面呈现如下(请注意缺少的引号/语法错误):
Currently, your page is rendered as follows (note the missing quotes / syntax error):
function redirect() {
window.location=http://www.newsite.com;
}
这篇关于PHP回应的Javascript不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!