Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace content in div after successful ajax function

Tags:

jquery

ajax

I would like to replace a content of <div id="container"></div> after the ajax function is successful, also without page refresh.

$.ajax({
      type: "POST",
      url: "scripts/process.php",
      data: dataString,
      success: function() {
        //Whats the code here to replace content in #conatiner div to:
        //<p> Your article was successfully added!</p>
      }
     });
    return false;
like image 597
Ilja Avatar asked Jun 22 '26 18:06

Ilja


1 Answers

http://api.jquery.com/html/

 $.ajax({
  type: "POST",
  url: "scripts/process.php",
  data: dataString,
  success: function( returnedData ) {
    $( '#container' ).html( returnedData );
  }
 });

also using http://api.jquery.com/load/,

$( '#container' ).load( 'scripts/process.php', { your: 'dataHereAsAnObjectWillMakeItUsePost' } );
like image 151
Dan Heberden Avatar answered Jun 24 '26 07:06

Dan Heberden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!