var url = interfaceURL;
var backUrl = interfaceBackURL;
var hardBackUrl = hardDataURL;
var cacheTime = 10day;
Ajax({
url: url,
backurl: backUrl,
success: function(){
// 缓存数据到本地
cache(DATAKEY, data, cacheTime);
show(data);
},
error: function(){
// 请求失败,获取本地缓存数据
var data = cache(DATAKEY);
if(data) {
Reporter.send(/*WARN*/);
show(data);
} else {
Reporter.send(/*ERROR*/);
_failed();
}
}
});
// 请求硬兜底
function _failed() {
Ajax({
url: hadrBackUrl,
success: function(data){
// 缓存数据到本地
cache(DATAKEY, data, cacheTime);
show(data);
},
error: function(){
Reporter.send(/*SUPER_ERROR*/);
show(data);
}
});
}
伪代码