qadenza
qadenza

Reputation: 9293

how to reload a page using ajax success function

admin.php

$.ajax({
        ...
        success: function() {
            location.href = "admin.php";
        }
    });

As a result I should get some new content added to the page (admin.php), but sometimes the page is not reloaded and I can see the new content only after pressing F5 key.

Any help?

Upvotes: 2

Views: 17954

Answers (3)

Florian
Florian

Reputation: 3171

Your success function should be:

success: function() {
  location.reload();
}

Upvotes: 4

suyesh
suyesh

Reputation: 659

you can call all the ajax method which are responsible to load the initial DOM on load. No need to refresh the page again.

function load(){
$.ajax({
        ...
        success: function() {
            //location.href = "admin.php";
            load();
        }
    });

}

load();

Something like above.

Upvotes: 1

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Try this:

success: function() {
            location.reload();    // to reload the same page again
            window.location.href = "admin.php";   // to go to a new url
        }

Upvotes: 2

Related Questions