[英]POST in PHP AND redirect the user to that page?
I'm a bit confused. 我有点困惑。 How do I POST data to a URL and then redirect the user's browser to that location - all in one operation?
如何将数据发布到URL,然后将用户的浏览器重定向到该位置 - 所有操作都在一个操作中?
I see 我懂了
header('Location: page.php?' . http_build_query($_POST));
but that is GET, not POST and ppl think thats really bad practice - PHP open another webpage with POST data (why?) 但这是GET,而不是POST和ppl认为这真的是不好的做法 - PHP用POST数据打开另一个网页 (为什么?)
My kludgy workflow involves setting up a form and then submitting it via javascript - anything has to be better than that... 我的kludgy工作流程涉及设置一个表单,然后通过javascript提交 - 任何东西都必须比那更好......
I think I can do a set of header() stmts but this action happens for the user way after the page has been geenrated, so i dont think that would work 我想我可以做一组header()stmts,但是这个动作是在页面被生成后以用户的方式发生的,所以我不认为这会起作用
You cannot redirect POST requests. 您无法重定向POST请求。 As simple as that.
就如此容易。 Any redirect will always turn into a GET request.
任何重定向都将始终变为GET请求。
If you want to receive POST data, then send that data to another page, you have two choices: 如果您想接收POST数据,然后将该数据发送到另一个页面,您有两个选择:
Use AJAX to save the data before you leave the page. 在离开页面之前使用AJAX保存数据。 Use the answer you get back to fire a redirection to the new url right within the current page.
使用您获得的答案在当前页面内向右侧激发重定向。 Don't be affraid of Javascript and ajax.
不要害怕Javascript和ajax。 Try this light AJAX library: http://www.openjs.com/scripts/jx/
试试这个轻量级AJAX库: http : //www.openjs.com/scripts/jx/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.