2017-02-14 67 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>