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

时间:2015-05-26 00:24:21

标签: 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('click', 'a.load-external', function(e){
var target = $( $(this).attr('data-target') );
target.load( $(this).attr('href') );
e.preventDefault();
});
</script>

content1.php

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

现在,在content1.php中,所有链接(a = href ...)运行良好并加载到#right_section div。

但是在content1.php上,我也有一些表单,我希望它们也可以加载到相同的div #right_section中。表格样本如下:

content1.php中的示例表单:

<form action="report_output.php" method="get" id="graphIt">

我怎样才能将一个表单(任何表单,可能是页面上的多个表格)加载到div #right_section中,而不加载整个页面(现在就是这样)

谢谢!

1 个答案:

答案 0 :(得分:2)

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

HTML:

{
 "1": {
  "100376": {
   "100377": {
    "100378": {},
    "100379": {
     "100380": {}
    }
   }
  }
 }
}

JS:

<form action="report_output.php" class="load-external" method="get" id="graphIt" data-target="#right_section">