2017-02-14 91 views
0

我在我的http中使用以下函数重定向到一些具有POST数据信息的URL。我需要将uuid1附加到新的url中,并将用户重定向到带有uuid信息的新页面http://localhost:8080/my_new_page.htmlPOST数据并重定向到一个url JavaScript

我能够看到POST数据的响应代码200,但它没有被重定向,当数据很大时,无法将样式表加载到我的新网址中。

我无法找到非重定向我的网址的原因。请帮助。

<input type="button" value="Click here to go back" onclick=postdata1(uuid1,respData);> 

function postdata1(uuid1,respData) { 
    var iframe = document.createElement("iframe"); 
    var uniqueString = "respData"; 
    document.body.appendChild(iframe); 
    iframe.style.display = "none"; 
    iframe.contentWindow.name = uniqueString; 

    var form = document.createElement("form"); 
    form.target = uniqueString; 
    form.action = 'http://localhost:8080/my_new_page.html?uuid='+uuid1; 
    form.method = "POST"; 

    var input = document.createElement("input"); 
    input.type = "hidden"; 
    input.name = "RespData"; 
    input.value = respData; 
    form.appendChild(input); 

    document.body.appendChild(form); 
    form.submit(); 
} 
+0

'uuid1'和'respData'在你的代码中的任何地方声明? – artur99

+0

是的。他们是。我也尝试在控制台上获取他们的输出。它在那里归还它们。 –

回答

1

你必须使用2个功能之一大厦HTML和下面的另一个为的onclick 是代码片段。这应该对你有所帮助。

<html> 
<body> 
<input type="button" value="Click here to go back" onclick=postdata1("Heell0o","Heell");> 


</body> 
<script> 
function loadForm(){ 

    var form = document.createElement("form"); 
    //form.target = uniqueString; 
    form.name = "RespDataForm"; 
    form.method = "POST"; 

    var input = document.createElement("input"); 
    input.type = "hidden"; 
    input.name = "RespDataInput"; 

    form.appendChild(input); 

    document.body.appendChild(form); 
} 

function postdata1(uuid1,respData) { 
console.log(uuid1+respData); 
    var form1 = document.getElementsByName("RespDataForm")[0]; 
    console.log(form1.name); 
     var input1 = document.getElementsByName("RespDataInput")[0]; 
    input1.value = respData; 
    form1.action = 'http://www.google.com?uuid='+uuid1; 
    form1.submit(); 
    return false; 
} 
loadForm(); 
</script> 
</html>