Reputation: 635
I have a webpage which displays all the records of a table with a checkbox infront of them. I can select the boxes and then make a ajax request for deleting them.
The deletion works fine. but even after refreshing it shows deleted records.
Things I used for redirection
-
window.location.href = '/current_page';
location.reload(true)
I used them success callback. If i click on browser then it works.
Upvotes: 1
Views: 2756
Reputation: 1715
No need for page refresh. You can delete the rows in the table using jQuery in your ajax success callback.
Upvotes: 0
Reputation: 4066
Try to use anchor to redirect by call the below function :
function redirectFunc(){
var link = document.createElement('a');
// set your page url
link.href = "url";
document.body.appendChild(link);
link.click();
}
Upvotes: 1
Reputation: 2387
The way you are trying to do is an hacky way. If you are trying to refresh the page then using location reload or anyother way then no point making an ajax call, you can simply make a delete call and target the page to a new url just like initial request.
This solution would be a bit bigger but scalable. I hope you might be rendering the initial table with some front end templating supplying some data as a model to the table. So on success of ajax request instead of reloading the page, try to reconstruct the DOM with the rest over data.
ex : model = {1,2,3} table contains 1 2 3
after delete update the model to 1 3 (if you have deleted 2) and call a render method of table with new model {1,3} erasing the old table. If you feel the data is too heavy (unless its too big) that it might really nag the user with performance you can go with this approach.
Upvotes: 0
Reputation: 2687
Use the Math.random for generate hash and put this in href of page. This well the page reload with no cache. The cache look adress page for query of content in cache.
Look this example:
function reloadWithNoCache(){
window.location = window.location.href + '?eraseCache=' + Math.random();
}
<input type="button" value="Refresh With No Cache" onclick="reloadWithNoCache()"/>
Upvotes: 0