Taco de Wolff
Taco de Wolff

Reputation: 1758

HTML change URL after an action-invoking-URL was processed

I find this problem hard to reword briefly in the title but this is what happens:

A page (domain.com/pages) shows for example a table with rows from the database and for each row I provide a 'Delete' button. This button redirects for example to (domain.com/pages/delete/5) when row with ID 5 is deleted. When loading the page, it recognizes row 5 needs to be deleted, so it does so. Afterwards it continues loading as if (domain.com/pages) was requested. So now the table shows again, with row ID 5 deleted and the URL in the address bar being (domain.com/pages/delete/5). When refreshing it reloads (domain.com/pages/delete/5) but I want it to reload (domain.com/pages).

So in short:

I don't want a redirect after the second link because I want to minimize redirection and keep site speed high. This could be fixed with AJAX calls, but that might complex things unnecessarily. Do I miss an easy way to make this action-invoking-URL just a one timer (ie. not invoked (accidentally) by refreshing)?

Upvotes: 0

Views: 200

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324760

You might be able to achieve this with the History API:

if( history.replaceState) history.replaceState(null,document.title,"/pages");

However, if you're interested in performance keep in mind that every time a row gets deleted, you're having to reload the entire table. Instead, you should use AJAX to request that the server delete the row, then use .removeChild() to remove the corresponding row from the table.

Upvotes: 3

Related Questions