2011-11-07 46 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覆蓋任何,並希望,在不透明背景。

相關問題