0

大家好,我是 PHP 新手

我正在使用 window.location 重定向到另一个 PHP 页面.. 但我需要向其中添加一些数据

所以我正在使用

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

但它对我不起作用,并在我的URL中给了我

http://bla bla/bla bla/post/view_full_post.php?ID=%3C?%20echo%20$ID%20?%3E

并说我正在传递有效的身份证件但它不起作用

不能接受的

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?

4

3 回答 3

2

您的以下代码不正确:

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

将其替换为以下内容:

echo '<script> window.location="../post/view_full_post.php?ID='.$ID.'"</script> ';
                                                             ^^^change here
于 2013-08-13T13:36:35.940 回答
2

尝试将其更改为

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

PHP 不会评估出现在半引号中的代码,您也不需要在代码行中间提供回显!

于 2013-08-13T13:36:54.657 回答
1

鉴于您已经在 PHP 中,您不需要 php 开始和结束标记。我会推荐这个:

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

但是,如果可以的话,我会在发送任何输出之前使用它。它会更快。

header('Location: http://example.com');
于 2013-08-13T13:37:32.657 回答