Page 75 - JavaScript修炼之道
P. 75
任务28 通过Ajax载入内容(同域名) 65
进行简单的Ajax请求
// Prototype
new Ajax.Request(url[, options])
new Ajax.Updater(container, url[, options])
// jQuery
$.ajax([settings])
// MooTools
new Request([options])
// YUI < 3
YAHOO.util.Connect.asyncRequest(method, url, callback, postData)
// YUI >= 3
Y.io(url[, config])
// Dojo
dojo.xhrGet(settings) // or xhrPost, xhrPut, xhrDelete.
// ExtJS
Ext.Ajax.request(settings)
尝试用更细化的、基于Prototype的Ajax
Ajax.Responders.register({
onCreate: function() { $('spinner').show(); },
onComplete: function() {
if (0 == Ajax.activeRequestCount)
$('spinner').hide();
}
});
new Ajax.Updater({ success: 'latestUsers' }, '/users/latest', {
method: 'get',
parameters: { mode: 'summary', threshold: 'auto' },
evalScripts: true,
onFailure: function() {
logError('We could not fetch the latest logged-in users, sorry.');
}
});