viktor.radovic
viktor.radovic

Reputation: 518

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>

Upvotes: 0

Views: 76

Answers (1)

derogab
derogab

Reputation: 152

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>

Upvotes: 1

Related Questions