3

I have from which will be submited to iframe:

<form id="myform" action="http://example.com/" target="myiframe">
     //some fields
</form>

<iframe name="myiframe" src=""></iframe>

Then on some point I submit this form with javascript:

<script type="text/javascript">
    document.getElementById("myform").submit();   
</script>

How to capture response after .submit()?

I can't use jQuery and Ajax call.

carpics
  • 2,272
  • 4
  • 28
  • 56

1 Answers1

1
  1. You might run into cross domain issues, since you won't be able to access http://example.com/ contents with JavaScript, unless your JavaScript is also hosted on http://example.com/.

  2. If form action leads to the same domain, you can do smth like this:

    html

    <form id="myform" action="http://fiddle.jshell.net/" target="myiframe">
         //some fields
    </form>
    
    <iframe id="myiframe" name="myiframe" src=""></iframe>
    

    javascript

    var iFrame = document.getElementById("myiframe");
    var form = document.getElementById("myform");
    
    iFrame.onload = function () {
        /** do smth with your iframe data */
        console.log(iFrame.contentDocument.body.innerHTML);
    };
    
    form.submit();
    

Please note the domain name in jsfiddle code - it points to the same domain, the JS is executed at, to prevent cross-domain access issues.

Anton Boritskiy
  • 1,539
  • 3
  • 21
  • 37