'abort', xhr, options)
},
xhr = {
abort: abort
}, abortTimeout
if (ajaxBeforeSend(xhr, options) === false) {
abort('abort')
return false
}
//成功加载后的回调函数
window[callbackName] = function(data) {
cleanup()
ajaxSuccess(data, xhr, options)
}
script.onerror = function() {
abort('error')
}
//将回调函数名追加到请求地址,并赋给script,至此请求产生
script.src = options.url.replace(/=\?/, '=' + callbackName)
$('head').append(script)
//如果设置了超时处理
if (options.timeout > 0) abortTimeout = setTimeout(function() {
abort('timeout')
}, options.timeout)
return xhr
}
//ajax全局设置
$.ajaxSettings = {
// Default type of request
type: 'GET',
// Callback that is executed before request
beforeSend: empty,
// Callback that is executed if the request succeeds
success: empty,
// Callback that is executed the the server drops error
error: empty,
// Callback that is executed on request complete (both: error and success)
complete: empty,
// The context for the callbacks
context: null,
// Whether to trigger "global" Ajax events
global: true,
// Transport
xhr: function() {
return new window.XMLHttpRequest()
},
// MIME types mapping
accepts: {
script: 'text/javascript, application/javascript',
json: jsonType,
xml: 'application/xml, text/xml',
html: htmlType,
text: 'text/plain'
},
// Whether the request is to another domain
crossDomain: false,
// Default timeout
timeout: 0,
// Whether data should be serialized to string
processData: true,
// Whether the browser should be allowed to cache GET responses
cache: true
};
//根据MIME返回相应的数据类型,用作ajax参数里的dataType用,设置预期返回的数据类型
//如html,json,scirpt,xml,text
function mimeToDataType(mime) {
if (mime) mime = mime.split(';', 2)[0]
return mime && (mime == htmlType ? 'html' : mime == jsonType ? 'json' : scriptTypeRE.test(mime) ? 'script' : xmlTypeRE.test(mime) && 'xml')
关键词:zepto是啥