简体   繁体   中英

Submit load page inside a DIV

I created this routine to do a submit and open a page inside a DIV. The javascript recognizes the DIV, but the page is opened overlaying the main page, outside the DIV. Does anyone know what the error could be?

Thanks

<head>
   <script>

      jQuery($ => {
      $('.e-chiedi').on('click', e => {
         let $btn = $(e.target);
         $.MessageBox({
                     buttonDone  : "Si",
                     buttonFail  : "No",
                     message     : "Mymessage"
                  }).done(function(){
                     document.getElementById("formHome").action = "inc_tessera.php#divTessera";
                     document.getElementById("formHome").submit();
                  }).fail(function(){
                     
                  });
      });
      });
</head>

<body>
   <div id="divTessera" style="display: none; ">divTessera</div>
   <input id="x" name="x" type="button" class="e-chiedi" data-message="test" />
</body>

When you submit a form (or follow a link) the result will be opened in a browsing context . That can be a window, a tab, or a frame. It cannot be a div.

You can either:

  • Replace the div with an iframe and use the target attribute on the form
  • Not submit a form and, instead, use the fetch API to make the HTTP request and DOM methods to display the result in the div.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM