使用ajaxfunction成功后显示消息

当ajax请求完成但我到目前为止没有运气时,我试图显示成功的消息。 这是html部分

  

这是ajax的一部分

 $(document).ready(function(){ $('.bookmarked', $('.buttons')).click(function(){ $.post('misc/add_favorites.php', { image_id: $(this).attr('id') }, success: function(){ $('#message').html('
Added to favorites!
'); // Diplay message with a fadeout $('#alertFadeOut').fadeOut(3000, function () { $('#alertFadeOut').text(''); }); }); console.log(data); }); });

在控制台我也得到了这个错误

参数列表后面的Uncaught SyntaxError:missing)

你不在post中使用success ,它与ajax不同

  

看到这可能有用

新编辑

在你的PHP文件中

  if($result > 0 ){ echo 1; } else { echo 0; } 

现在你的函数在你的ajax调用中

 function(data){ if(data == 1){ $('#message').html('
Added to favorites!
'); // Diplay message with a fadeout $('#alertFadeOut').fadeOut(3000, function () { $('#alertFadeOut').text(''); }); } }