Javascript jQuery-在父页面的DIV(?)中加载表单提交

Javascript jQuery-在父页面的DIV(?)中加载表单提交,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,我有下面的代码,它工作得很好。。。目前为止但我想下一步有一个表单加载。。。请阅读下面的代码以获得解释 主页: <li><a href="content1.php" class="load-external" data-target="#right_section">Some Content</a></li> <div id="right_section"></div> <script> $('body').on

我有下面的代码,它工作得很好。。。目前为止但我想下一步有一个表单加载。。。请阅读下面的代码以获得解释

主页:

<li><a href="content1.php" class="load-external" data-target="#right_section">Some Content</a></li>
<div id="right_section"></div>

<script>
$('body').on('click', 'a.load-external', function(e){
var target = $( $(this).attr('data-target') );
target.load( $(this).attr('href') );
e.preventDefault();
});
</script>
<form action="report_output.php" method="get" id="graphIt">
  • $('body')。在('click','a.load-external',函数(e)上{ var target=$($(this.attr('data-target')); target.load($(this.attr('href')); e、 预防默认值(); });
    content1.php

    <li><a href="content2.php" class="load-external" data-target="#right_section">Some Content 2</a></li>
    
  • 现在,在content1.php中,所有链接(a=href…)都工作正常,并加载到#right_部分div中

    但是在content1.php上,我也有一些表单,我希望它们也加载到同一个div#right_部分。表格样本如下所示:

    content1.php中的示例表单:

    <li><a href="content1.php" class="load-external" data-target="#right_section">Some Content</a></li>
    <div id="right_section"></div>
    
    <script>
    $('body').on('click', 'a.load-external', function(e){
    var target = $( $(this).attr('data-target') );
    target.load( $(this).attr('href') );
    e.preventDefault();
    });
    </script>
    
    <form action="report_output.php" method="get" id="graphIt">
    
    
    
    如何让表单(任何表单,页面上可能有多个表单)加载到div#right_部分,而不加载整个页面(现在是这样)


    谢谢

    您需要替换表单的提交处理程序,类似于替换链接上的普通单击处理程序

    HTML:


    所有内容都应该加载到DIV中。我看不出表单有任何不同的原因。你是说当你提交其中一个表单时,其结果应该加载到DIV中,而不是重新加载页面?正确。。。但是现在,它只是覆盖了整个浏览器窗口。谢谢。我想JS会出现在主页上。。。试过了,但不起作用。JS中应该有对#right_部分或数据目标的引用吗?我已经尝试了很多方法,但它不想工作。
    $(this)。data('target')
    获得了
    数据目标。
    。好的,我让它工作了。非常感谢。我在report_output.php页面(预加载程序)中有一个div导致了这个问题。。。。