On a certain page I have a button / link written "Favor"
<a href="SITE.COM/post/favoritar/ID" class="btn-favorite-normal">Favoritar</a>
Where ID is the publication id, but I already have a script in PHP that will insert and remove the database.
When the post is favored or is already marked as favorite, the script returns a {"favorite:1"}
JSON and when it is not marked as favorite or the bookmark is removed, the script returns {"favorite:0"}
.
from these values I would like to change the state of the button with AJAX, for example: when clicking the favorite button, and everything happens correctly, the script will return {"favorite:1"}
and the name of the "Favor" button will become "Favored" ", the link ( href ), and the style class will also change to eg
<a href="SITE.COM/post/favoritar/ID/remover" class="btn-favorite-ativo">Favoritado</a>
was added in the URL, after the ID, the name "remove"; the button name changed to "favored"; and the btn-favorite-normal class changed to btn-favorite-active;
"remove" in the URL that will remove the favorites, which when clicked will return {"favorite:0"}
and the button would return to its normal state, written "favorite" and with the default link favor.