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