Replace content in div after successful ajax function

前端 未结 2 460
一个人的身影
一个人的身影 2020-12-21 13:40

I would like to replace a content of

after the ajax function is successful, also without page refresh.

         


        
2条回答
  •  -上瘾入骨i
    2020-12-21 14:38

    You can set the "context" for an ajax request which then is passed into the success handler. In there, you might just call .html() to replace the content.

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

    Your article was successfully added!

    '); } });

    Ref.:

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

提交回复
热议问题