1
On a certain page I have a button/link written "Bookmark"
<a href="SITE.COM/post/favoritar/ID" class="btn-favorite-normal">Favoritar</a>
Where the ID is the post id, but anyway, I already have a PHP script that takes care of entering into the database and remove.
when the post is favored or already marked as favorite, the script returns a JSON {"favorite:1"}
and when it is not bookmarked or the bookmark tag is removed, the script returns {"favorite:0"}
.
apart from these values I would like to change the status of the button with AJAX, for example: by clicking the favorite button, and everything occurs correctly, the script will return {"favorite:1"}
and the name of the "Favorite" button will be "Favorite", the link(href), and the style class will also change to, ex:
<a href="SITE.COM/post/favoritar/ID/remover" class="btn-favorite-ativo">Favoritado</a>
was assigned to the URL, after the ID, the name "remove"; the name of the button has been changed to "favorite"; and the btn-Favorite-normal class has changed to btn-Favorite-active;
the "remove" in the URL you will remove from the bookmarks, which you click will return {"favorite:0"}
and the button would return to its normal state, written "favorite" and with the default link to bookmark.
The correct is to return {Favorite:0} or {Favorite:1}
– Hiago Souza
without the quotation marks?
– Thiago
Without the quotation marks... what is your backend language? if php vc can do this echo json_encode(array('Favorite' => 0)); or echo json_encode(array('Favorite' => 1));
– Hiago Souza
yes, to using php, I was giving an echo "{Favorite:0}", this json function Ncode returned with quotes, {"Favorite":1}
– Thiago
Yeah, use it the way I pointed out:)
– Hiago Souza