简体   繁体   English

在 DIV 中提交加载页面

[英]Submit load page inside a DIV

I created this routine to do a submit and open a page inside a DIV.我创建了这个例程来执行提交并在 DIV 中打开一个页面。 The javascript recognizes the DIV, but the page is opened overlaying the main page, outside the DIV. javascript 可以识别 DIV,但在 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.这可以是 window、选项卡或框架。 It cannot be a div.它不能是 div。

You can either:您可以:

  • Replace the div with an iframe and use the target attribute on the form将 div 替换为 iframe 并使用表单上的target属性
  • 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.不提交表单,而是使用fetch API发出 HTTP 请求和DOM 方法以在 div 中显示结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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