这是我的第一个问题。我一直在搜索Stack Overflow和其他Web资源,但我无法找到FullCalendar正确接受jQuery数据属性所需的可靠答案。
我的意思是我有一个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”:“无效的JSON原语:owner_email。”,“StackTrace”:“at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject(个)\ r \ n 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(的Int32 深度)\ r \ n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串 输入,Int32 depthLimit,JavaScriptSerializer序列化程序)\ 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](字符串 输入)\ r \ n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext的 context,JavaScriptSerializer序列化程序)\ r \ n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData,HttpContext context)\ r \ n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HTTP [...]
答案 0 :(得分:0)
我想您使用的是> = .NET 3.5
问题是:您的数据格式不正确。尝试使用JSON.stringify()并生成JSON数据,如果您不想要JSON2.js,请尝试手动以适当的JSON格式创建数据。
如果将数组作为JSON返回,Fullcalendar可以很好地解决问题。
您将获得与start参数相同的错误消息。问题在于fullcalendar尝试将start和end参数附加到您的数据,但start和end不是JSON格式。因此,您必须转到fullcalendar.js并在函数_fetchEventSource(source,callback)中编辑以下内容。
$.ajax($.extend({}, ajaxDefaults, source, {
data: JSON.stringify(data),
success: function (events) {
events = events.d;
............................
在您的网络服务中: -
PS:不要尝试将webservice中的列表转换为任何格式。只需返回List对象。在成功事件中,您必须从名为“d”的“密钥”中获取JSON对象,因为在新版本中,它将对象封装在名为“d”的密钥中以进行ajax调用。所以使用该密钥访问它。
您的网络服务签名(示例):
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Object> functionName(argumentList)
{ return ObjectList;}
如果您使用XML返回,那么您必须在javascript和call中以适当的格式创建event []对象 - &gt;要显示fullcalendar的回调(事件)。