HTTP POST and competent degradation

I have a web application that, among other things, contains a table of elements created using an Ajax callback. A bunch of form fields at the top of the table allows me to filter the elements that will be displayed in the table according to various criteria and show them.

In some parts of the table there are lists of elements marked with [X] next to them, which can be deleted by clicking on these elements.

Now, if I were to do this non-ajax / javascript, the page would receive a bunch of POSTed data fields and then display the table accordingly. I can do this, but I would also like to Ajaxify the entire installation. My questions concern this.

  • How to create a [X] button. A simple one <a>will "work", but this changes the state of the GET, so I don't want to do this. The way I am doing this now is a tiny form with a hidden parameter, which holds the element to be deleted, and a stylized submit button, which is [x]. If I ajaxify this, I can get an answer and do the necessary.

  • How do I save my backend DRY? I do not want to have two completely different code bits for Ajaxified and regular. What I'm doing right now is to send the version without the ajax to a URL that changes state and then redirected to the main page again (similar to a system like PRG). When Ajax is enabled, I just call the URL and ignore the redirect, but use the returned data to set up the table. Is this the "right way"?

  • Any other graceful degradation tips on how to keep my backend DRY?

+3
source share
1 answer

( method='POST') , , . [X] , , XmlHttpRequest , , ( , POST).
XmlHttpRequest, POST , , , . AJAX, , (200 OK).

+3

Source: https://habr.com/ru/post/1770572/


All Articles