Error - Error: Uncaught SyntaxError: Unexpected token :
平台 - Icenium。剑道UI - 错误:未捕获的SyntaxError:意外的标记:
我们正在使用Remote Service - http://localhost:35798/RestServiceImpl.svc/json
来获取数据。我附加了从服务收到的数据格式。
这里是我的代码:
var dataSource = new kendo.data.DataSource({
schema: {
data: "d"
},
transport: {
read: {
url: "http://localhost:35798/RestServiceImpl.svc/json",
dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
data: {
id: "4"
},
type: "GET",
contentType: "application/json;charset=utf-8"
},
change: function() {
alert('called');
var data = this.data();
console.log(data.length); // displays "77"
debugger;
$('#txtJson').val(data[0].name);
}
}
});
$("#submitButton").click(function() {
dataSource.read();
var data = dataSource.data();
console.log(data.length);
});
这里是我的服务代码 -
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json?id={id}")
]
List<Person> JSONData(string id);
,Q 1)如何解决这个错误 - Uncaught SyntaxError: Unexpected token
,我失去的东西吗?
问2)点击按钮后,我打电话dataSource.read()
,之后dataSource.data().length
越来越0.我认为这应该在dataSource.bind(change:function())
处理。但是,dataSource.read()
更改功能不会触发。
您不包括图像! – OnaBai
我已添加图片。我希望你清楚我在找什么。我还指定了图像中从服务返回的数据。谢谢, –
你是否意识到你没有返回JSONP,而是一个JSON?这是“意外令牌”错误的原因。 – OnaBai