2011-11-07 22 views
0

使用缓慢的AJAX向用户显示“加载...”是一件好事。 现在我有历史工作使用'history.pushState'和'hostory.popState' 但它并没有显示我的加载图像,同时执行实际ajax按钮后按!如何在使用AJAX工作时在POPSTATE之前和之后绑定?

$(window).bind("popstate", function() { 
    $.get(location.href); 
    //$.getScript(location.href); 
}); 

怎么做类似$(window).bind("before_popstate", function() {});

BTW I`M运行在后台的Rails ...

PSS

$(document).ready(function(){ 
    $(window).bind("popstate", function() { 
    $.get(location.href); 
    }); 

$('.remote') 
.bind("ajax:beforeSend", function(evt, xhr, settings){ 
     $('#mainframe').html(""); 
     $('#loading').toggle(); 
    }) 
.bind("ajax:success", function(evt, data, status, xhr){ 
    $('#loading').toggle(); 
}) 
.bind('ajax:complete', function(evt, xhr, status){ 
     history.pushState(null, document.title, path) 
}) 
.bind("ajax:error", function(evt, xhr, status, error){ 
     $('#mainframe').html("error"); 
     $('#loading').toggle(); 

}); 

回答

0

如何:

$(window).bind("popstate", function() { 
    your-showAjaxLoader-function() 
    $.get(location.href); 
    //$.getScript(location.href); 
    your-removeAjaxLoader-function() 
}); 

要么 这种性质的东西。我自己有ajaxLoader-GIF在呼叫之后或通话中被称为历史预处理器和ajaxLoader-GIF卸妆器。

更新: 我看到您正在切换三个绑定的“加载”但未完成。我,我自己,如果必须嵌套命令,请避免使用toggle。在开始时,您可以使用.show()和其他所有的.hide()。

现在回到真正的问题:“加载不显示”。它看起来像代码明智一切都好。你确定“< img src”在你的代码中是否正确“加载”?

+0

不幸的是,它不适合我。 *)甚至不知道为什么*((((( – prikha

+0

你好prikha,你能展示更多的代码吗? –

+0

来看看吧! – prikha

0

还有一件事:你确定z-index的加载和位置是正确的吗?我假设你想LOADING覆盖任何,并希望,在不透明背景。

相关问题