Aja.js異步JS和JSON數(shù)據(jù)請求
aja.js 主要用于異步JS文件和JSON數(shù)據(jù)的請求,不支持XML請求。
JSON 數(shù)據(jù)請求
aja()
.url('/api/data.json')
.on('success', function(data){
//data is a JavaScript object
})
.go();
請求載入 HTML
aja()
.url('/views/page.html')
.into('.container')
.go();
REST 客戶端
aja()
.method('GET')
.url('/api/customer')
.timeout(2500)
.data({firstname: 'John Romuald'})
.on('200', function(response){
//well done
})
.on('timeout', functon(){
// uh oh... Request ended. Do something fancy here, don't let your user wait forever!
})
.go();
aja()
.method('PUT')
.url('/api/customer')
.cache(false)
.body({id : 12, firstname: 'John Romuald', job : 'linguist'})
.on('200', function(response){
//well done
})
.on('40x', function(response){
//something is definitely wrong
})
.on('500', function(response){
//oh crap
})
.go();
JSON
aja()
.url('http://otherdomain.com/api/remoteScript')
.type('jsonp')
.jsonPaddingName('callbackParameter')
.jsonPadding('someGlobalFunction')
.on('success', function(data){
//Fuk cross origin policy
})
.go();
載入JS
aja()
.url('http://platform.twitter.com/widgets.js')
.type('script')
.on('success', function(){
window.twttr.widgets.load();
})
.go();評論
圖片
表情

