Aja.js异步JS和JSON数据请求
aja.js 主要用于异步JS文件和JSON数据的请求,不支持XML请求。
JSON 数据请求
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();评论

