1
我有這個簡單的代碼,現場直播(點擊:)外部鏈接通過ajax()調用。只有在阿賈克斯發射功能({成功:})函數轉換爲實時({和成爲ajax({beforeSend:成功後全部被觸發:
這裏的代碼:
$('.ajaxLink').live({
click : function(e) {
$this = $(this);
var myLink = $this.attr('href');
var myId = $this.attr('id');
e.preventDefault();
$('html,body').animate({ // this is fired only AFTER content load
scrollTop : 0
}, 1500);
$.ajax({ type: 'GET',
url: myLink,
async: false,
dataType: 'html',
beforeSend : function() {
caricaModal.open(); // this is also fired only after content load
}, // is just an animation on a div.
success : function(page) {
caricaModal.close(); // this is fired at good timing
// some more code here where I insert (page) in the DOM
}
});
}
});
如果你想知道多少時間,這需要加載它需要大約1.5秒,頁面和肯定的,事實是,當我點擊沒有發生什麼之前,事情已經加載並插入到DOM。
任何想法?
這是否意味着async:和beforeSend:不能住在一起? – Daniele 2012-01-11 23:37:33
嗯。這就是它的樣子,但除非你能證明它,否則你無法確定。它似乎確實有道理。 – karim79 2012-01-11 23:38:18