2017-02-14 7 views
0

httpで次の機能を使用して、POSTデータ情報を含むURLにリダイレクトしています。 uuid1に新しいURLを追加して、ユーザーに新しいページhttp://localhost:8080/my_new_page.htmlをuuid情報でリダイレクトする必要があります。POSTデータとURLにリダイレクトするJavaScript

POSTデータのレスポンスコード200が表示されていますが、リダイレクトされていません。データが大きい場合は、新しいURLにスタイルシートをロードできません。

私のURLのリダイレクトの理由を見つけることができません。親切に助けてください。あなたは以下のonclick のために2つの機能ビルHTML用と別のものを使用する必要が

<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

は、コードスニペットです。これはあなたを助けるはずです。

<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> 
関連する問題