使用Javascript - 重定向到用POST数据页 [英] Javascript - redirect to a page with POST data

查看:156
本文介绍了使用Javascript - 重定向到用POST数据页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,用户可以搜索(全部AJAX)在数据库中进行选择,让我们说,不同类型的页面上的数据。当的,他选择了他们,我需要的是将用户重定向到另一个页面(仍然在我的网站虽然),用POST数据。 新的页面,用户将到达该职位数据需求,用户需要进入新的一页。

I've got a page where the user can search (all in AJAX) in the database and select, let's say, different type of data on the page. When's he chosen them, what I need is to redirect the user to ANOTHER page (still on my website though), with POST data. The new page where the user will arrive needs that POST data, and the user needs to go to the new page.

我读过,我可以加载页面之前创建一个表单,并请提交它时,我想重定向,但事情是,我没有将包含在之前手上的数据。

I've read that I could create a form before loading the page and simply submit it when I want to redirect, but the thing is that I don't have the data that will be included in the before hand.

我试着做这样的事情:

document.write('<form id="reviseCombi" method="post" action="otherPage.php"><input name="input1" type="hidden" value="ok" /><input type="input2" type="hidden" value="'+ mots +'" /></form>');
f=document.getElementById('reviseCombi');
if(f){
    f.submit();
}

但第二次输入不到达新的页面时,我请与篡改数据。它首先重新加载实际的页面,这是奇怪的了。

But the second input doesn't arrive to the new page when I check with Tamper Data. And it reloads the actual page first, which is weird too.

有没有更好的办法做到这一点?

Is there a better way to do it?

编辑:我得到的输入部分答案。页面现在得到两个输入端。但是:它仍然只重新加载包含窗体(和HTML,身体等)的空白页面,然后将其重定向。任何想法如何,我可以直接把它?

I got an answer for the input part. The page now gets the two inputs. But: it still reloads a blank page ONLY containing the form (and the html, body, etc.) and then it redirects. Any idea how I can have it directly?

很抱歉,如果这不是很清楚,这是很难解释。我会回答任何评论来解释它更好。 非常感谢。

Sorry if it's not very clear, it's tough to explain. I'll answer any comments to explain it better. Thanks alot.

推荐答案

问:但是第二次输入不到位的新的一页

Q: "But the second input doesn't arrive to the new page"

答:您的第二个输入没有名字! (键入 =输入2让名称 =输入2)

A: Your second input does NOT have name! (type="input2" make it name="input2")

问:它第一次重新加载实际的页面,这是不可思议了。

Q: "And it reloads the actual page first, which is weird too."

答:如果您使用的是Firefox,你回波数据之前的&lt; DOCTYPE>和&lt; HTML>标签,你会得到一个自动刷新。如果你想调试,呼应里面的&lt数据; BODY>

A: If you are using firefox and you echo data before the < DOCTYPE > and < HTML > tags, you get an auto refresh. if you wish to debug, echo data inside the < BODY >

A2:可能是陌生的重载是因为你正在做外的&lt形式的文件撰写; BODY>或者内部的&lt; HEAD> ...如果多数民众赞成的情况下,为什么不这样做的:

A2: Its possible that the strange reload happens because you are doing that document.write of the form outside the < BODY > or maybe inside the < HEAD > ... if thats the case why not doing this:

HTML

<div id="myformcontainer"></div>

JS

function CreateAFormInsideMyDivAndSubmitIt(mots)
{
    var mydiv = document.getElementById('myformcontainer').innerHTML = '<form id="reviseCombi" method="post" action="otherPage.php"><input name="input1" type="hidden" value="ok" /><input name="input2" type="hidden" value="'+ mots +'" /></form>';
    f=document.getElementById('reviseCombi');
    if(f){
    f.submit();
    }
}

的jsfiddle: http://jsfiddle.net/MDx8H/1/ (警报,而不是的提交)

jsfiddle: http://jsfiddle.net/MDx8H/1/ (alerts instead of submits)

这篇关于使用Javascript - 重定向到用POST数据页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆