1

I am using the following function in my http to redirect to some url with the POST data information. I need to append the uuid1 with the new url and redirect the user to the new page http://localhost:8080/my_new_page.html with the uuid information.

I am able to see the response code 200 for the POST data but it is not being redirected, and when data is large, is unable to load the style sheets in my new url.

I am not able to find the reason for non-redirection of my url. Kindly help.

<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();
}
Daksh Agarwal
  • 167
  • 2
  • 12

1 Answers1

3

you have to use 2 functions one for Building HTML and another for onclick below is the code snippet. This should help you.

<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>
3bu1
  • 977
  • 12
  • 30