Cakephp - Jquery JSOn Ajax 调用在空闲时间后不发送任何数据
没关系,我只是发现 CakePHP 必须重新设置 cookie,因为它过期了。如果您遇到相同的错误,只需使用 Firebug => 检查返回标头即可“设置 Cookie”。
我有一个 jquery 函数,它使用 Ajax 调用 CakePHP 函数并将其作为 JSON 返回:
$('#categories a').live('click', function() {
catid = $(this).attr('id');
load_notes(catid);
return false;
});
function load_notes(catid){
$.ajax({
type: 'POST',
url: '/notes/load_notes',
data: 'category_id='+catid,
dataType: 'json',
success: function(data){
jQuery.each(data, function(i) {
new_note = '';
new_note = build_note(this.Note.id, this.Note.content);
new_note.appendTo('#notes').hide().fadeIn(i*300);
//new_note.appendTo('#notes').hide().fadeIn(1000);
//new_note.appendTo('#notes');
});
},
error:function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
}
在文档准备好并且单击类别链接后,将调用“load_notes”。当我刚刚加载页面或几分钟后单击类别链接时,这工作正常。但是当我等待大约 30 分钟并触发该函数时,没有返回任何内容(因此无法显示注释)。 只有当我重新加载页面时,该功能才能再次正常工作。
我通常会得到一个 JSON 数组作为响应(使用 Firebug 检查),但是当错误发生时,我只得到:
“j 为空”handleError(a=Object { url =“/notes/load_notes”,全局= true, 更多...}, b=XMLHttpRequest { onreadystatechange=[xpconnect 已包装 nsIDOMEventListener],readyState=4, 更多...}, d="成功", e=null)
有什么线索可能会导致这种情况吗?有人经历过类似的事情吗?
Nevermind, I just figured out that CakePHP had to re-set the cookie because it expired. If you experience the same error, just check the return header with Firebug => "Set-Cookie".
I have a jquery function which calls a CakePHP Function with Ajax and returns it as JSON:
$('#categories a').live('click', function() {
catid = $(this).attr('id');
load_notes(catid);
return false;
});
function load_notes(catid){
$.ajax({
type: 'POST',
url: '/notes/load_notes',
data: 'category_id='+catid,
dataType: 'json',
success: function(data){
jQuery.each(data, function(i) {
new_note = '';
new_note = build_note(this.Note.id, this.Note.content);
new_note.appendTo('#notes').hide().fadeIn(i*300);
//new_note.appendTo('#notes').hide().fadeIn(1000);
//new_note.appendTo('#notes');
});
},
error:function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
}
"load_notes" is called after the document is ready and if I click on a Category-Link. This works fine when I just loaded the page or when I click on a category-link after a few minutes. But when I wait for around 30 minutes and fire the function, nothing is returned (therefore the notes can't be displayed).
Only if I reload the page, the function works fine again.
I usually get a JSON-Array as a response (checked with Firebug) but when the error occurs, I only get:
"j is null" handleError(a=Object {
url="/notes/load_notes", global=true,
more...}, b=XMLHttpRequest {
onreadystatechange=[xpconnect wrapped
nsIDOMEventListener], readyState=4,
more...}, d="success", e=null)
Any clue what could cause this? Anyone experienced something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个firebug问题,而不是jquery。我有时会在 Firebug 中遇到同样的错误(完全随机),当我重新启动浏览器时它会解决。
也许是一个愚蠢的问题但是..你尝试过其他浏览器/控制台吗?使用 Chrome 后我再也没有遇到过这个问题。
It seems a firebug problem, not jquery. I get this same error with firebug sometimes (fully randomly) and it solves when I restart the browser.
Maybe is a stupid question but.. have you tried with other browsers / consoles?? With Chrome I haven't had this problem again.