I would like to be able to star/un-star any given conversation (like Gmail for example.) When I click the "empty" star to mark something as important, I need to submit some ajax and then toggle to the star image. And visa versa, when I click a starred conversation, I need the ajax to submit and upon its success, then have "empty" star toggled back.
Some HTML (in a nutshell):
<div class='__conversation'>
<div class='__conversation_star'>
<img class='__star_n' src='p_star_n.png'/>
<img class='__star_y' src='p_star_y.png'/>
</div>
</div>
And something with similar functionality to a basic:
$(".__conversation_star").click(function() {
$(this).find('img').toggle();
});
Some ajax:
$(".__conversation_star").click(function() {
jQuery.ajax({
type: 'POST',
url: "./process.conversation.php,
data: {method: 'star'},
cache: true,
success: function() {
// Toggle to un-starred .__star_n
}
});
});
$(".__conversation_star").click(function() {
jQuery.ajax({
type: 'POST',
url: "./process.conversation.php",
data: {method: 'star'},
cache: true,
success: function() {
// Toggle to starred .__star_n
}
});
});
Is there a way I can perform a toggle upon success of the ajax? and/or what other methods of doing this are there that will work better?
Thank you!