由网友(书蝶)分享简介:我想显示消息的成功时,Ajax请求完成,但至今没有运气。这是HTML的一部分< A HREF =#级=书签了,提示数据标题=加入收藏ID =$行['image_id']。 '>&所述; / a取代;<跨度ID =消息>< / SPAN>这是AJAX部分$(文件)。就绪(函数(){...
我想显示消息的成功时,Ajax请求完成,但至今没有运气。 这是HTML的一部分
< A HREF =#级=书签了,提示数据标题=加入收藏ID =$行['image_id']。 '>&所述; / a取代;
<跨度ID =消息>< / SPAN>
这是AJAX部分
$(文件)。就绪(函数(){
$('书签',$('按钮'))。点击(函数(){
.post的$('杂项/ add_favorites.php',{
image_id:$(本).attr('身份证')},
成功:函数(){
$('#消息)HTML('< DIV ID =alertFadeOut的风格!=颜色:绿色>添加为收藏< / DIV>'); //用淡出Diplay消息
$('#alertFadeOut)。淡出(3000,函数(){
$('#alertFadeOut)文本('')。
});
});
的console.log(数据);
});
});
此外,在控制台中我得到这个erroe
未捕获的SyntaxError:之后的参数列表缺失)
解决方案您不使用成功
内后,其不一样的AJAX
<脚本>
$(文件)。就绪(函数(){
$('书签',.buttons)。点击(函数(){
.post的$('杂项/ add_favorites.php',
{
image_id:$(本).attr('身份证'),
},
功能(){
$('#消息)HTML('< DIV ID =alertFadeOut的风格!=颜色:绿色>添加为收藏< / DIV>'); //用淡出Diplay消息
$('#alertFadeOut)。淡出(3000,函数(){
$('#alertFadeOut)文本('')。
});
});
的console.log(数据);
});
});
< / SCRIPT>
看这可能工作
新修改
在你的PHP文件
如果($结果> 0){
回声1;
} 其他 {
呼应0;
}
现在你对你的Ajax调用内部函数
功能(数据){
如果(数据== 1){
$('#消息)HTML('< DIV ID =alertFadeOut的风格!=颜色:绿色>添加为收藏< / DIV>'); //用淡出Diplay消息
$('#alertFadeOut)。淡出(3000,函数(){
$('#alertFadeOut)文本('')。
});
}
}
I've trying to display message for success when ajax request finish but no luck so far. This is the html part
<a href="#" class="bookmarked has-tooltip" data-title="Add to favorite" id="'.$row['image_id'].'"></a>
<span id="message"></span>
and this is the ajax part
$(document).ready(function(){
$('.bookmarked', $('.buttons')).click(function(){
$.post('misc/add_favorites.php', {
image_id: $(this).attr('id') },
success: function(){
$('#message').html('<div id="alertFadeOut" style="color: green">Added to favorites!</div>'); // Diplay message with a fadeout
$('#alertFadeOut').fadeOut(3000, function () {
$('#alertFadeOut').text('');
});
});
console.log(data);
});
});
Also in console I got this erroe
Uncaught SyntaxError: missing ) after argument list
解决方案
You dont use success
within post, its not same as ajax
<script>
$(document).ready(function(){
$('.bookmarked', .buttons').click(function(){
$.post('misc/add_favorites.php',
{
"image_id": $(this).attr('id'),
},
function(){
$('#message').html('<div id="alertFadeOut" style="color: green">Added to favorites!</div>'); // Diplay message with a fadeout
$('#alertFadeOut').fadeOut(3000, function () {
$('#alertFadeOut').text('');
});
});
console.log(data);
});
});
</script>
see this may work
New edit
In you php file
if($result > 0 ){
echo 1;
} else {
echo 0;
}
Now your function inside your ajax call
function(data){
if(data == 1){
$('#message').html('<div id="alertFadeOut" style="color: green">Added to favorites!</div>'); // Diplay message with a fadeout
$('#alertFadeOut').fadeOut(3000, function () {
$('#alertFadeOut').text('');
});
}
}
相关推荐
最新文章