//My web-service method WebService1.asmx
[WebMethod]
[ScriptMethod]
public string GetAllEvents()
{
var list = new List<string>();
list.Add("[{\"id\":\"36\"title\":\"Birthday party\",\"start\":\"2013-09-18\",\"end\":\"2013-09-18\",\"allDay\":false}]");
JavaScriptSerializer jss = new JavaScriptSerializer();
string strJSON = jss.Serialize(list.ToArray());
return strJSON;
}
//My jQuery snippet
$("#fullcalendar").fullCalendar({
eventSources:
[
{
url: "http://localhost:49322/WebService1.asmx/GetAllEvents",
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
}
]
});
回答
你在錯誤的軌道上。
- 不要使用字符串操作手動形成你的json字符串(就你而言,它是一個無效的json)。
- 不要從Web方法返回的字符串,返回真正的對象
應該是這樣的:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Event> GetAllEvents()
{
List<Event> events = .......
..fill the list....
return evetns;
}
public class Event
{
public int id { get; set; }
public string title { get; set; }
public string start { get; set; }
public string end { get; set; }
public bool allDay { get; set; }
}
public class Events { public string start; 公共字符串標題; } 公共列表
@ChaitanyaMoganti不需要手動將對象序列化爲json。它會自動完成,請參閱屬性('[ScriptMethod(ResponseFormat = ResponseFormat.Json)]') – I4V
$( 「#fullcalendar」)fullCalendar({ eventSources: [ { 網址:「HTTP: //localhost:49322/WebService1.asmx/GetAllEvents」, 類型: 'POST', 數據類型: 「JSON」, 的contentType: 「應用程序/ JSON;字符集= UTF-8」, } ] }); 它不工作如果我喜歡這樣做.. –
- 1. 日曆天渲染事件
- 2. 完整日曆不渲染事件?
- 3. 日曆組件不渲染
- 4. 渲染JSON事件的完整日曆
- 5. jQuery完整日曆渲染事件
- 6. 爲什麼不NoMatch渲染
- 7. 這爲什麼不渲染?
- 8. 爲什麼不是Bootstrap Jumbotron渲染?
- 9. jQuery Frontier日曆不在IE 8中渲染事件
- 10. 爲什麼React組件不渲染?
- 11. UI日曆不工作,不渲染
- 12. 全日曆刷新事件
- 13. 的iOS EventKit - 事件不是從日曆
- 14. Marionette.ItemView渲染事件
- 15. 全日曆事件數據
- 16. 爲什麼不渲染爲表HTML
- 17. 複合社區事件日曆和表單渲染器
- 18. 什麼是渲染數據
- 19. 什麼是渲染asp.mvc
- 20. 爲什麼Html.ActionLink渲染
- 21. 全日曆事件不起作用
- 22. 查看是不是重新渲染,不知道爲什麼
- 23. 爲什麼只渲染頂層組件?
- 24. 爲什麼不在窗口中渲染?
- 25. 爲什麼我的rich:dataTable不能渲染?
- 26. 爲什麼不渲染@search工作?
- 27. 爲什麼IE8不能渲染?
- 28. 全日曆顯示全天事件
- 29. 爲什麼DataPager需要預渲染事件?
- 30. BHO渲染事件
請提供更多的信息(例如你的HTML丟失)或 - 甚至更好 - 把一個jsFiddle放在一起。 – chopper
對於它的價值,我最近發佈了一些關於如何使用ASHX文件執行此操作的C#代碼:http://mikesmithdev.com/blog/fullcalendar-json-feed-httphandler-csharp/如果這是一個選項而不是web服務,讓我知道,我會張貼代碼作爲答案。 – MikeSmithDev