我正在尝试创建一种通用的方式来在我的网页中调用 ajax 请求。 我创建了一个不错的小扩展方法来异步调用 post 请求。
$.tiqPost = function(action,data,callback)
{
alert('Posting...');
$.fancybox.showActivity();
$.ajaxSetup({async:true});
$.post('/portfolios/mod/t:'+action+'/',data,function(response)
{
callback(response);
$.fancybox.hideActivity();
alert('Finished Post.');
});
alert('Posting Set.');
}
但是,每当此请求触发时,我的页面都会无限期冻结。在某些版本的 Chrome 中,它会冻结且没有反馈(单击停止工作,我无法关闭选项卡(。 不过,它大多数其他浏览器都显示"发布",然后在没有达到"发布集"或"完成的帖子"的情况下停止。
所以Chrome没有发现任何错误,只是冻结。这让我非常费解。 有人有任何提示(甚至只是不同的实现(?
编辑:
并非每个请求都会发生这种情况。 事实上,让我发布一些它有效的案例和一些它不起作用的情况。坚持。。。
编辑编辑:
所以在这个例子中
$.tiqPost('newcat',{t:"n"},function(response)
{
if(response)
{
$tabs.tabs('add','#tiq-tab-'+response,"New Category",0);
}
});
我没有问题。 然而:
$(this).bind('blur',function(postdata)
{
//blur
if(postdata==null)
postdata = {value:$(this).text()};
$.tiqPost($(this).attr('id').replace('tiq-submit-',''),
postdata,
function (response) {
$(this).text(response);
});
$(this).removeClass('tiq-editable-editstate');
$(this).attr('contentEditable','false');
});
导致冻结。
做
$.post('/portfolios/mod/t:'+action+'/',data,function(response)
{
callback(response);
alert('Finished Post.');
});
一个人,有效吗?如果是这样,则可能在配置函数本身时遇到问题