Reputation: 141
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
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¶m2=2'
Upvotes: 0
Reputation: 897
There are 2 ways where you can use to redirect/refresh the page.
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.
You can also use window.location.href = "https://www.url.com/";
where you can redirect it to specific page.
Upvotes: 0
Reputation: 832
location.reload();
Moreover, you may check it out w3schools from here.
Upvotes: 0
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