2014-04-28 38 views
0

我有一個導航欄,所有調用都設置爲data-remote=true。如果用戶點擊導航欄上的其他項目,我想中止請求。 看來我需要撥打.abort(),但我如何從軌道link_to做到這一點?如何調用abort()data-remote = true

回答

1

還沒有嘗試過,但是您可能會將XMLHttpRequest保存在ajax:beforeSend回調中,並中止以前的請求。例如:

var currentRequest; 
$('your-nav-items').on('ajax:beforeSend', function(event, xhr, settings) { 
    if (currentRequest) currentRequest.abort(); 
    currentRequest = xhr; 
}); 
+0

完美,謝謝。我對文檔進行了綁定,並在導航功能上處理中止。 – user2590365

相關問題