How do I submit a form correctly via ajax inside an iframe?

  • 0
    Confused and don't understand why this is happening.
    When trying to select a file inside the iframe (ajax must press submit) - the html parent is loaded into the iframe, and the form is not submitted. Help me decide!

    There is a parent page with an embedded iframe
    <iframe src="index_frame.php" name="index_frame"></iframe>


    Inside index_frame.php:
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js" ></script>
    
    <script type="text/javascript">
    <!--
    $(window).ready(function(){
        $("#files").change(function() {
                     this.form.submit();
                });
    });
    //-->
    </script>
    
    <form action="./" method="post" id="uploadform" onsubmit="return false;" style="display:none;" target="index_frame">
      <input type="file" id="files" name="files[]" accept="video/*"> 
      </form>
    AJAX Nora Horn, Dec 6, 2019

  • 1 Answers
  • 0
    If the parent is loaded, then the address to which you submit the form is the parent. Make sure you pass the form wherever you need to, try to specify not a relative, but a full link to the php handler in the action instead.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!