0

I have a HTML form, that POSTs data to an application. The submit action has stopped POSTing anything to the application because as per the browser console. "Form is not connected".

I read an answer about this potential problem here. And I tried to attach the form to the body as mentioned in the accepted answer. But even then the POST request doesn't go through because the form is disconnected.

To provide an idea of what is exactly happening I am providing a snippet of my code:

<body>
<form action="BiApi/a/b" method="post" id="formquery" name= "makeQuery">

<!--Some text boxes and a submit button-->

</form>
<script>    
var form=document.getElementById('formquery');
document.body.appendChild(form);
form.addEventListener('submit', function (event) {
document.write("<h1>Running Request, please wait...</h1><a   href='https://www.mywebsite.com/a/b.html' >Go Back</a>");

this.style['display'] = 'none';
});

</script>
</body>

In the code I am appending the form to the body but no data is posted even after submit button is clicked.

Any solution?

Thank You.

Community
  • 1
  • 1
krazzy12
  • 11
  • 2
  • Remove the `document.write(...)` – Andreas Feb 11 '17 at 19:15
  • When you post something in a HTML form the page is reset by the way. And why document.write() ? you can use a hidden div and make it appear. – zakaria amine Feb 11 '17 at 19:23
  • How will removing document.write() help? @Andreas ? – krazzy12 Feb 12 '17 at 19:45
  • The `document.write(...)` is executed before the form is submitted. Because of the way `document.write` [works](https://developer.mozilla.org/en-US/docs/Web/API/Document/write#Notes), the form is destroyed before it can be submitted. Check the network panel in the developer tools. With `document.write(...)` there will be no request. – Andreas Feb 13 '17 at 08:26
  • Got it. It did solve the issue. Thanks Andreas! – krazzy12 Feb 13 '17 at 20:48

0 Answers0