当我尝试使用来自服务器的数据加载Simile时间线时,我收到以下消息:
Failed to load json data from
{"events":
[{
"description":"Oswald moves to New Orleans, and finds employment at the William B. Riley Coffee Company.",
"end":"Wed May 01 1969 00:00:00 GMT-0600",
"isDuration":true,
"start":"Wed May 01 1963 00:00:00 GMT-0600",
"title":"Oswald moves to New Orleans"}]}
Bad Request
我认为数据看起来是正确的。
以下是触发请求的代码:
$(document).ready(function () {
$.ajax({
url: "http://localhost:64510/api/timeline",
type: "GET",
dataType: "json",
contentType: "application/json",
success: function (data) {
loadTimeLine(data);
}
});
});
function loadTimeLine(data) {
var eventSource = new Timeline.DefaultEventSource();
var bandInfos = [
Timeline.createBandInfo({
eventSource: eventSource,
date: "Jun 28 2006 00:00:00 GMT",
width: "70%",
intervalUnit: Timeline.DateTime.MONTH,
intervalPixels: 100
}),
Timeline.createBandInfo({
eventSource: eventSource,
date: "Jun 28 2006 00:00:00 GMT",
width: "30%",
intervalUnit: Timeline.DateTime.YEAR,
intervalPixels: 200
})
];
bandInfos[1].syncWith = 0;
bandInfos[1].highlight = true;
tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
Timeline.loadJSON(JSON.stringify(data), function (xml, url) { eventSource.loadJSON(xml, url); });
}
答案 0 :(得分:0)
解决方案是在从服务器创建响应时必须添加状态代码200。