继上一个问题之后,(上一个问题 https://stackoverflow.com/questions/3916829/jquery-ajax-cookie),如果检测到 cookie,我似乎无法“触发”ajax 调用。 cookie 肯定已设置,并且显示了警报,但我一生都无法让它再次触发 ajax 调用。我只需要它在检测到 cookie 的情况下在加载页面时“触发”ajax,而不是使用“更多”按钮。
希望这是有道理的。非常感谢任何帮助。 S。
$(document).ready(function(){
$(function() {
//More Button
$('.more').live("click",function()
{
$.cookie('viewing_expanded_content',true, { expires : new Date(new Date().valueOf() + 60 * 60 * 1000) });
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="images/more_press.gif" alt="More results..." />');
$.ajax({
type: "POST",
url: "more_press.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
}
});
} else {
$(".morebox").html('<p><strong>No more results...</strong></p>');
//$.cookie('viewing_expanded_content', null);
}
return false;
});
});
var viewing_expanded_content = $.cookie('viewing_expanded_content');
if ( viewing_expanded_content == 'true' ) {
alert("Active cookies!");
//my proposed call that doesnt work
$.ajax({
type: "POST",
url: "more_press.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
}
});
}
})
EDIT: 工作解决方案在这里... https://stackoverflow.com/questions/3958860/jquery-ajax-cookie-call
要放置错误回调函数,您可以这样做
//my proposed call that doesnt work
$.ajax({
type: "POST",
url: "more_press.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
},
error: function(){
// write your code for error handling
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)