here is the code I'm using:
$(function() {
$(".fav").click(function() {
var page = $('#page').attr('value');
var user = $('#user').attr('value');
var time = $('#time').attr('value');
var info = "page="+ page +"& user="+ user +"& time="+ time;
$("#loading").html('<im g src="loader.gif" />');
$.ajax({
type: "POST",
url: "favorite.php",
data: info,
success: function() {
$("#loading").ajaxComplete(function(){}).slideUp();
$('#fav').fadeOut(200).hide();
$('#unfav').fadeIn(200).show();
}
});
return false;
});
});
</script>
<script type="text/javascript" >
$(function() {
$(".unfav").click(function(){
var page = $('#page').attr('value');
var user = $('#user').attr('value'开发者_Go百科);
var info = "page="+ page +"& user="+ user;
$("#loading").html('<im g src="loader.gif" />');
$.ajax({
type: "POST",
url: "notfavorite.php",
data: info,
success: function(){
$("#loading").ajaxComplete(function(){}).slideUp();
$('#unfav').fadeOut(200).hide();
$('#fav').fadeIn(200).show();
}
});
return false;
});
});
Everything is working fine, it acts as a "like" "follow" button, the only problem is that the ajaxComplete() function only runs once.
Cheers!
$(function(){
$(".fav").click(function(){
var page = $('#page').attr('value');
var user = $('#user').attr('value');
var time = $('#time').attr('value');
var info = "page="+ page +"& user="+ user +"& time="+ time;
$("#loading").html('<im g src="loader.gif" />');
$('#follow').hide();
$.ajax({
type: "POST",
url: "favorite.php",
data: info,
success: function(){
$('#loading').empty();
$('#remove').fadeIn(200).show();
}
});
return false;
});
})();
same for .unfav
精彩评论