使用 AJAX 重新加载 PHP FORM


Reloading PHP FORM using AJAX

在我的门户网站中,我有一个页面index.php <div>标签,其中的内容是使用AJAX获取的。此时<div>标记调用index2.php页面。在页面index2.php有一个表单,应该使用AJAX提交(不刷新整个页面,只是刷新index2.php)。提交后,应再次调用index2.php,但从形式(超过 POST 个)中带有一些额外的参数。

问题是因为POST请求已发送,但看起来<div>index2.php)的内容没有更改。这是代码:

索引.php

 <div id="left_side">
       <h3>Toolbar</h3>
 </div>
  <div id="content">
      there will be refreshed index2.php
  </div>
  ......
   function doAjax() {
          var frm = $('#plotForm1');
          $.ajax({
              type: frm.attr('method'),
              url: frm.attr('action'),
              data: frm.serialize(),
              success: function (data) {
                            }
             });    
     }

索引2.php

<form id="plotForm1" action="index2.php" onsubmit='doAjax(); return false;' method="post">
 ....
</form>

索引.php

<div id="left_side">
       <h3>Toolbar</h3>
 </div>
  <div id="content">
      there will be refreshed index2.php
  </div>
  ......
   function doAjax() {
          var frm = $('#plotForm1');
          $.ajax({
              type: frm.attr('method'),
              url: frm.attr('action'),
              data: frm.serialize(),
              success: function (data) {
$('#content').html(data);
                            }
             });    
     }

索引2.php

<form id="plotForm1" action="index2.php" onsubmit='doAjax(); return false;' method="post">
 ....
</form>