product.js
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define(['jquery', 'underscore', 'text!../html/templates/product.html'], function($, _, Tpl) {
var Page = {
initialize: function(opt) {
this.opt = opt;
this.bindEvents();
this.render();
},
bindEvents: function() {
},
render: function() {
var _this = this,
opt = {
data: {
// modelCode: "nfyx"
modelCode: this.opt.modelCode
},
success: function(response) {
if (response.code == 200) {
response.wap = _this.opt.wap;
response.banner = _this.opt.banner;
response.title = _this.opt.title;
$('.m-page').html(_.template(Tpl)(response));
} else {
alert('请求数据失败,未知错误!');
}
},
error: function() {
alert('未知错误!');
}
};
this.request(opt);
},
request: function(opt) {
$.ajax({
type: 'POST',
data: JSON.stringify(opt.data),
url: 'http://mobapi.nong12.com/mobsiteApp/topic/getTopicProducts.do',
// url: 'http://10.28.2.183/mobsiteApp/topic/getTopicProducts.do',
async: true,
timeout: 15000,
dataType: 'json',
contentType: "application/json; charset=utf-8"
}).done(function(data) {
opt.success && opt.success(data);
}).fail(function(xhr, ajaxOptions, thrownError) {
alert('网络连接超时或失败!');
console.log('error code: ' + xhr.status + '\n ajaxOptions:' + ajaxOptions + '\n message: ' + thrownError + '\n APIName:' + opt.apiName);
});
}
};
return Page;
});