J.Pei
J.Pei

Reputation: 141

How to reload ajax url after post to php?

Here, I use ajax post some data to my PHP file, how to reload the URL(PHP) under the success function? window.location.reload(); doesn't work.

function saveChanges(arr){
                       $.ajax({
                        data: { rowdata:arr, editingid:rowId },
                        url: '../app/course.php',
                        method: 'POST',
                        success: function(){
                            //reload url here

                        }
                    });

                    }//end of saveChanges()

Upvotes: 0

Views: 337

Answers (4)

Gufran Hasan
Gufran Hasan

Reputation: 9373

I think this should work (Not Tested).

function saveChanges(arr){
var url = window.location.href; 
    $.ajax({
       data: { rowdata:arr, editingid:rowId },
       url: '../app/course.php',
       method: 'POST',
       success: function(success){
         if(success){
           // do something here
             window.location.href = url; // reload the page
          }
       }
   });

}//end of saveChanges()

if you want to add some parameters in URL you can add it before reloading the page as:

url +='?param1=1&param2=2'

Upvotes: 0

Bits Please
Bits Please

Reputation: 897

There are 2 ways where you can use to redirect/refresh the page.

  1. You can simply use the JavaScript location.reload() method to refresh or reloads the page. This method optionally accepts a Boolean parameter true or false. If the parameter true is specified, it causes the page to always be reloaded from the server. However, if it is false (which is default) or not specified, the browser may reload the page from its cache.

  2. You can also use window.location.href = "https://www.url.com/"; where you can redirect it to specific page.

Upvotes: 0

Nazmus Shakib
Nazmus Shakib

Reputation: 832

location.reload();

Moreover, you may check it out w3schools from here.

Upvotes: 0

Virb
Virb

Reputation: 1578

You can use location.reload(); after ajax success.

function saveChanges(arr){
    $.ajax({
       data: { rowdata:arr, editingid:rowId },
       url: '../app/course.php',
       method: 'POST',
       success: function(){
          location.reload();
       }
   });

}//end of saveChanges()

Upvotes: 1

Related Questions