我希望能够为任何给定的对话加注星标/取消加注星标(例如 Gmail。)当我单击“空”星标将某些内容标记为重要时,我需要提交一些 ajax,然后切换到星标图像。反之亦然,当我单击加星标的对话时,我需要 ajax 提交并在其成功后,然后将“空”星切换回来。
一些 HTML(简而言之):
<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>
和基本功能类似的东西:
$(".__conversation_star").click(function() {
$(this).find('img').toggle();
});
一些阿贾克斯:
$(".__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
}
});
});
有没有办法在ajax成功后执行切换?和/或有什么其他方法可以更好地工作?
谢谢!