小编典典

成功的ajax功能后,替换div中的内容

ajax

我想<div id="container"></div>在ajax函数成功后替换内容,也无需刷新页面。

$.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;

阅读 475

收藏
2020-07-26

共1个答案

小编典典

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

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

也使用http://api.jquery.com/load/

$( '#container' ).load( 'scripts/process.php', { your: 'dataHereAsAnObjectWillMakeItUsePost' } );
2020-07-26