成功的ajax函数后替换div中的内容

在ajax函数成功后,我想替换

的内容,也没有页面刷新。

 $.ajax({ type: "POST", url: "scripts/process.php", data: dataString, success: function() { //Whats the code here to replace content in #conatiner div to: //

Your article was successfully added!

} }); return false;

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' } ); 

您可以为ajax请求设置“context”,然后将其传递给success处理程序。 在那里,您可以调用.html()来替换内容。

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

Your article was successfully added!

'); } });

参考:

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