2011-11-23 62 views
1

这是我的第一个问题。我一直在搜索Stack Overflow和其他Web资源,但我无法找到FullCalendar正确接受jQuery数据属性所需的确切答案。contentType属性应用程序/ xml工作出错,但应用程序/ json不是

我的意思是说,我有一个Web服务,它接受一个字符串作为其所需的参数。我要打电话给这个* owner_email *

Web服务将采用该参数并返回由FullCalendar呈现的UserAssignments的数组。

我遇到了* owner_email *从jQuery/FullCalendar到ASP.NET Web服务的实际传递问题。当我将contentType更改为'application/xml'或将其注释掉时,它将返回一个空的XML文档(我现在想要的),但是当我将其更改回'application/json'时,会发生错误json格式。任何帮助表示赞赏。另外,我想知道在FullCalendar上放置什么活动。

这里是我迄今所做的代码:
的JavaScript:

$("#calendar").fullCalendar({ dayClick: function() { alert('a day was clicked!'); }, eventSources: [ 

// your event source { url: "WebService.asmx/displayUserAssignments", type: 'POST', data: { owner_email: 'test' }, processData: true, dataType: "json", contentType: 'application/json', color: 'yellow', // a non-ajax option textColor: 'black' // a non-ajax option } // any other sources... ] 

ASP.NET代码片段:

[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public UserAssignments[] displayUserAssignments(string owner_email) { int totalAssignments = 0; int current_index = 0; UserAssignments[] compiled_user_assignments; OracleConnection openedConnection = new OracleConnection(WebConfigurationManager.ConnectionStrings["BehemothConn"].ConnectionString); openedConnection.Open(); OracleCommand query = new OracleCommand("SELECT * FROM personal_assignments_view where owner_email = :input_email", openedConnection); OracleCommand numberOfRows = new OracleCommand("select count(*) from personal_assignments_view where owner_email = :input_email", openedConnection); 

query.Parameters.Add(":input_email", OracleType.VarChar).Value = owner_email; numberOfRows.Parameters.Add(":input_email", OracleType.VarChar).Value = owner_email; 

OracleDataReader returned_result = numberOfRows.ExecuteReader(); returned_result.Read(); totalAssignments = returned_result.GetInt32(0); 

compiled_user_assignments = new UserAssignments[totalAssignments]; returned_result = query.ExecuteReader(); 

while (returned_result.Read()) { compiled_user_assignments[current_index] = new UserAssignments(); compiled_user_assignments[current_index].assignment_id = returned_result.GetInt32(0); compiled_user_assignments[current_index].owner_email = returned_result.GetString(1); compiled_user_assignments[current_index].assignment_name = returned_result.GetString(2); compiled_user_assignments[current_index].assignment_date = returned_result.GetOracleDateTime(3).Value.ToString("R"); compiled_user_assignments[current_index].assignment_description = returned_result.GetString(4); compiled_user_assignments[current_index].event_id = returned_result.GetInt32(5); compiled_user_assignments[current_index].week_day = returned_result.GetString(6); compiled_user_assignments[current_index].is_deleted = returned_result.GetString(7); compiled_user_assignments[current_index].start_time = returned_result.GetInt32(8); compiled_user_assignments[current_index].end_time = returned_result.GetInt32(9); compiled_user_assignments[current_index].is_completed = returned_result.GetString(10); compiled_user_assignments[current_index].pan_note_id = returned_result.GetInt32(11); compiled_user_assignments[current_index].pan_assign_id = returned_result.GetInt32(12); compiled_user_assignments[current_index].assignment_note = returned_result.GetString(13); current_index++; } 

openedConnection.Close(); openedConnection.Dispose(); return compiled_user_assignments; } 

UserAssignments类:

public class UserAssignments { public int assignment_id; public string owner_email; public string assignment_name; public string assignment_date; public string assignment_description; public int event_id; public string week_day; public string is_deleted; public int start_time; public int end_time; public string is_completed; public int pan_note_id; public int pan_assign_id; public string assignment_note; 

public UserAssignments() { assignment_id = -1; owner_email = ""; assignment_name = ""; assignment_date = ""; assignment_description = ""; event_id = -1; week_day = ""; is_deleted = ""; start_time = -1; end_time = -1; is_completed = ""; pan_note_id = -1; pan_assign_id = -1; assignment_note = ""; } } 

jQuery的错误:

{"Message":"Invalid JSON primitive: owner_email.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(Http[...]

+0

我已经决定使用xml返回,但我怎么能够正确地格式化输出xml for fullcalendar解析? –

回答

0

我想你使用的是> = .NET 3.5

的问题是:你的数据不正确JSON格式。尝试使用JSON.stringify()并生成JSON数据,如果您不需要JSON2.js,请尝试手动以适当的JSON格式创建数据。

如果您将数组作为JSON返回,Fullcalendar运行良好,没有太多黑客行为。

您将得到相同的启动参数错误消息。问题在于fullcalendar试图将开始和结束参数附加到您的数据,但开始和结束不是JSON格式。所以你必须得到fullcalendar.js并编辑下面的函数_fetchEventSource(source,callback)。

$.ajax($.extend({}, ajaxDefaults, source, { 
         data: JSON.stringify(data), 
         success: function (events) { 
          events = events.d; 
          ............................ 

而在你的web服务: -

PS:不要试图在列表转换内部web服务的任何format.Just返回List对象。在成功事件中,您必须从名为'd'的'key'中获取JSON对象,因为在新版本中,它将对象封装在名为'd'的键中以用于ajax调用。因此,使用该密钥访问它。

您的Web服务的签名(例如):

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public List<Object> functionName(argumentList) 
    { return ObjectList;} 

Webservice response captured using Firebug 如果你是在XML返回,那么你必须在你的JavaScript和call--内适当格式创建您的活动[]对象>回调(事件)为fullcalendar显示。

+0

我能够使用FullCalendar获得XML。但是,我没有意识到ASP.NET会自动创建单独的元素,而不是将其序列化到一个XML字段中。 'System.Xml'和'System.Xml.Serialization'类以及'XmlAttributeAttribute'属性都有帮助。谢谢您的帮助! 对不起格式正确。我是通过电话发布的。 –

相关问题