2012-05-01 55 views
1

我是wordpress的新手。将参数传递给javascript中的location.href而不是头文件()

我曾尝试下面的代码

header("Location: $location", true, $status); 

我想重定向的页面,特定页面和我得到这样的错误

"Cannot modify header information - headers already sent by (output started at /home/content/c/l/a/clareb23/html/client4/wp-content/plugins/featured-articles-lite/main.php:773) in /home/content/c/l/a/clareb23/html/client4/wp-includes/pluggable.php on line 870" 

的任何建议,将不胜感激。基于评论

+0

如果您在WordPress的工作,那么你应该更好地利用wp_redirect()http://codex.wordpress.org/Function_Reference/wp_redirect – Anand

+0

我使用'wp_redirect()',但它与插件代码冲突的.. 。 –

回答

1

你可以这样说:

<script> 
    window.location = '<?php echo $location?>?myvar=true&status=<?php echo $status?>'; 
</script> 

确保你没有以前header(...)声明呼应屏幕/打印任何东西,没有打开php标签前的空格,例如<?php。在header()功能后放exit()也是一个好习惯。

+0

是的,但我不希望使用标题(...),而不是我想要重定向的JavaScript页面并想通过“真”和“$状态”作为参数... –

+0

@HeerMakwana:看更新的答案plz。 – Sarfraz

+0

你是对的...但在我的情况下,它不能正常工作。我不是获取参数其他地方,我只是重定向到指定的页面。这种“?MYVAR =真状态= <?PHP的echo $状态?>”将通过这些参数作为查询字符串。没有办法摆脱这里... –