Sugam
Sugam

Reputation: 635

Page reload after ajax request for delete

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

-

I used them success callback. If i click on browser then it works.

Upvotes: 1

Views: 2756

Answers (4)

Cheezy Code
Cheezy Code

Reputation: 1715

No need for page refresh. You can delete the rows in the table using jQuery in your ajax success callback.

Upvotes: 0

Osama AbuSitta
Osama AbuSitta

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

Rajendra kumar Vankadari
Rajendra kumar Vankadari

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

Emir Marques
Emir Marques

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

Related Questions