PHP Window.location可以';不接受查询字符串

PHP Window.location可以';不接受查询字符串,php,window,location,query-string,Php,Window,Location,Query String,大家好,我是PHP新手 我正在使用window.location重定向到另一个PHP页面。。但我需要补充一些数据 所以我用 echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> '; 并告诉我我正在传递有效的ID,但它不起作用 不可接受 An appropriate representation of the requested resour

大家好,我是PHP新手

我正在使用window.location重定向到另一个PHP页面。。但我需要补充一些数据

所以我用

echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> ';
并告诉我我正在传递有效的ID,但它不起作用

不可接受

An appropriate representation of the requested resource /bla bla/post/view_full_post.php could not be found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

所以我的问题是如何将查询字符串传递到Window.location

您的以下代码不正确:

echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> ';
echo'window.location=“../post/view_full_post.php?ID=“”;
将其替换为以下内容:

echo '<script> window.location="../post/view_full_post.php?ID='.$ID.'"</script> ';
                                                             ^^^change here
echo'window.location=“../post/view_full_post.php?ID=”.$ID.“;
^^^在这里换车

您的以下代码不正确:

echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> ';
echo'window.location=“../post/view_full_post.php?ID=“”;
将其替换为以下内容:

echo '<script> window.location="../post/view_full_post.php?ID='.$ID.'"</script> ';
                                                             ^^^change here
echo'window.location=“../post/view_full_post.php?ID=”.$ID.“;
^^^在这里换车
尝试将其更改为

echo '<script> window.location="../post/view_full_post.php?ID=' . $ID . '"</script> ';
echo'window.location=“../post/view_full_post.php?ID=”.$ID.”;

PHP不评估在半引号中出现的代码,也不需要在代码行的中间提供回音! 尝试将其更改为

echo '<script> window.location="../post/view_full_post.php?ID=' . $ID . '"</script> ';
echo'window.location=“../post/view_full_post.php?ID=”.$ID.”;

PHP不评估在半引号中出现的代码,也不需要在代码行的中间提供回音! 既然已经使用了PHP,就不需要PHP的开始和结束标记。我建议:

echo "<script> window.location=\"../post/view_full_post.php?ID=$ID\"</script> ";

由于您已经使用了PHP,所以不需要PHP的开始和结束标记。我建议:

echo "<script> window.location=\"../post/view_full_post.php?ID=$ID\"</script> ";

这就是为什么我更喜欢为此使用
sprintf()
函数的原因…这就是为什么我更喜欢为此使用
sprintf()
函数的原因…如果您使用header('Location:);您可能需要ob_start();在文档顶部。@rsmith为什么要添加所有这些转义符来迷惑眼睛。有关正确/优雅的操作方法,请参见其他2个答案。@riggsfully以便我们可以在字符串中包含变量?@rsmith他还使用PHP编写了一些javascript代码,以便在发送页面后在浏览器中运行。在PHP中运行
header()
函数抛出另一个页面到底有什么意义?阅读,消化,思考,……回答。@RiggsFolly“他正在使用PHP编写一些javascript代码,以便在发送页面后在浏览器中运行”啊,是的,因为有太多合法的理由让人想这样做,然后重定向,如果你做了标题('Location:);您可能需要ob_start();在文档顶部。@rsmith为什么要添加所有这些转义符来迷惑眼睛。有关正确/优雅的操作方法,请参见其他2个答案。@riggsfully以便我们可以在字符串中包含变量?@rsmith他还使用PHP编写了一些javascript代码,以便在发送页面后在浏览器中运行。在PHP中运行
header()
函数抛出另一个页面到底有什么意义?阅读,消化,思考,……回答。@RiggsFolly“他正在使用PHP编写一些javascript代码,以便在页面发送后在浏览器中运行”啊,是的,因为有很多合法的理由让人想这样做,然后重定向