1

I have a small project using MVC5, C# and jQuery with Bootsrap.

In my web app I am loading a partial view dynamically using Ajax, like in the example below:

$.get(refreshTable, function (data) {
    $("#packagesTable").replaceWith(data);
});

Everything works fine excpet for one little detail: I want to run a success notification only when the partial view finishes loading:

successNotification("Package edited successfuly!");

Is this possible? and if yes, how?

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
  • Why not just put it in after the replaceWith(data)? At this point the html is download and inserted into the page. Or do you have more activity happen in the partial view? – Steve Lillis Dec 04 '14 at 16:18

3 Answers3

2

There is a call back function called done. Run your code here. It'll execute after successfully executed

var jqxhr = $.get( "example.php", function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })

Refer : http://api.jquery.com/jquery.get/

Jeeva J
  • 3,173
  • 10
  • 38
  • 85
0

You might be able to extend the replaceWith function call to accept a CallBack function that will run once the replaceWith call is completed. This SO has a sample implementation.

Community
  • 1
  • 1
mreyeros
  • 4,359
  • 20
  • 24
0

It sounds like you want to make use of the deferred object in your call.

So it would look like this:

    $.get(refreshTable, function(data) {
        $("#packagesTable").replaceWith(data)
            .done(function() {
                alert("$.get succeeded");
            });
    });
BryanOfEarth
  • 715
  • 11
  • 26