简体   繁体   中英

Reloading PHP FORM using AJAX

In my web portal, I have one page index.php which have <div> tag which content is obtained using AJAX . At this <div> tag the page index2.php is called. At the page index2.php there is one form which should be submitted using AJAX (without refreshing whole page, just refreshing index2.php ). After submit, index2.php should be again called but with some additional arguments from form (over POST ).

Problem is because POST request is sent, but it looks like content of <div> ( index2.php ) is not changed. Here is the code:

index.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) {

                            }
             });    
     }

index2.php

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

index.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);

                            }
             });    
     }

index2.php

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

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