版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25354709/article/details/88066364
一、Zepto.js的AJAX常见开发模式
这种是单例模式
//->MATCH INFO
var matchRender = (function () {
var $matchInfo = $('.matchInfo'), //获取容器
$matchInfoTemplate = $('#matchInfoTemplate'); //获取模板
//->BIND HTML
function bindHTML(matchInfo) {
//->使用ejs模板引擎
$matchInfo.html(ejs.render($matchInfoTemplate.html(), {matchInfo: matchInfo}));
}
return {
/* init 是当前的入口 */
init: function () {
//->GET DATA
$.ajax({
url: 'http://matchweb.sports.qq.com/html/matchDetail?mid=100000:1468531&_=1472982271063&callback=jsonp1',
dataType: 'jsonp',
success: function (result) {
if (result && result[0] == 0) {
result = result[1];
var matchInfo = result['matchInfo'];
matchInfo['leftSupport'] = result['leftSupport'];
matchInfo['rightSupport'] = result['rightSupport'];
//->BIND HTML
bindHTML(matchInfo);
}
}
});
}
}
})();
matchRender.init();