Error - Error: Uncaught SyntaxError: Unexpected token :
플랫폼 - Icenium.검도 UI - 오류 : catch되지 않은 구문 에러 : 예기치 않은 토큰 :
우리는 데이터를 얻을 원격 서비스 - 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
을, 내가 놓친 게 뭔가?
Q 2) 버튼을 클릭 한 후 dataSource.data().length
이 0이되고 난 후에 dataSource.read()
을 호출하고 있습니다. 이것은 dataSource.bind(change:function())
에서 처리해야한다고 생각합니다. 그러나 이후 dataSource.read()
변경 기능이 실행되지 않습니다.
당신은 이미지를 포함하지 않았다! – OnaBai
이미지를 추가했습니다. 내가 원하는 것을 가지고 당신이 분명하기를 바랍니다. 또한 이미지에서 서비스에서 반환되는 데이터를 지정했습니다. 감사합니다, –
JSONP가 아니라 JSON을 반환하고 있다는 것을 알고 계셨습니까? 그것이 "예기치 않은 토큰"오류의 원인입니다. – OnaBai