我是淘汰赛并试图创建我的第一个基于JSO脚本更新的脚本。问题是我似乎得到一个意外的错误:Uncaught SyntaxError:意外的标识符。
<head>
<script type='text/javascript' src='knockout-3.3.0.js'></script>
<script type="text/javascript">
callService();
var Match = function(){
var self = this;
self.matches = ko.observableArray();
self.ajax = function (uri, method, data) {
var request = {
url: uri,
type: method,
contentType: "application/json",
accepts: "application/json",
cache: false,
dataType: 'json',
data: JSON.stringify(data),
error: function (jqXHR) {
console.log("ajax error " + jqXHR.status);
}
};
return $.ajax(request);
}
function callService(){
self.ajax(url + "matchticker.json" + requestData, 'GET').done(function (data) {
self.matches.removeAll();
for(int i = 0; i < data.Result.length; i++){
self.matches.push(..data..);
}
}
}
}
ko.applyBindings(new Match());
</script>
</head>
<body>
<ul class="list-group col-sm-12 col-xs-12" data-bind='foreach: matches'>
<li data-bind="html: match_id"></li>
</ul>
</body>
答案 0 :(得分:0)
这里有很多语法错误。下次尝试首先使用linting代码。 看看它是否有效:
var Match = function(){
var self = this;
self.matches = ko.observableArray();
self.ajax = function (uri, method, data) {
var request = {
url: uri,
type: method,
contentType: "application/json",
accepts: "application/json",
cache: false,
dataType: 'json',
data: JSON.stringify(data),
error: function (jqXHR) {
console.log("ajax error " + jqXHR.status);
}
};
return $.ajax(request);
};
function callService(){
self.ajax(url + "matchticker.json" + requestData, 'GET').done(function (data) {
self.matches.removeAll();
for(var i = 0; i < data.Result.length; i++){
self.matches.push(data.Result[i]);
}
});
}
callService();
};
ko.applyBindings(new Match());