前端提交javascript
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MeetingOneWeekNotifyList.aspx.cs" Inherits="MeetingOneWeekNotifyList" %> <%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %> <%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %> <asp:content id="ContentHead" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server"> <%-- <link href="commom_new_shenergy.css" rel="stylesheet" />--%> <link href="commom_new_201611081702.css" rel="stylesheet" /> <script src="js/jquery-1.11.3.min.js"></script> <script type="text/javascript"> $.ajax({ url: "./Handler/HandlerMeetList.ashx",//查詢 type: "post", async: false, dataType: "json", data: { }, success: function (arr) { for (var i = 0; i < arr.length; i++) { var en = arr[i]; alert(en.MeetTitle); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); function Save() { var entity = {}; entity.MeetId = 1; entity.MeetTitle = "bbbb"; $.ajax({ url: "./Handler/HandlerMeetReq.ashx",//查詢 type: "post", async: false, dataType: "text", data: { method: "ADD", req: JSON.stringify(entity) }, success: function (arr) { alert(arr); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } function Save() { var entity = {}; entity.MeetId = 1; entity.MeetTitle = "bbbb"; $.ajax({ url: "./Handler/HandlerMeetReq.ashx",//查詢 type: "post", async: false, dataType: "text", data: { method: "Del", req: JSON.stringify(entity) }, success: function (arr) { alert(arr); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } </script> </asp:content> <asp:content id="Content1" contentplaceholderid="PlaceHolderMain" runat="Server"> <input type="button" value="Update" onclick="Save()" /> <div class="wrap"> <div class="contentDiv"> <div class="inCon" > <div class="right"> <div class="InRight">一週會議通知 <a href="http://tuvaudit:41182/_layouts/15/shenergy/MeetingOneWeekApplyForm.aspx" style="color:white;margin-left:65%">+新增會議申請</a> </div> <div class="tableDiv" > <table cellpadding="0" cellspacing="0" width="100%" id="meetingNotifyOneWeekTable"> <tr> <td>序列號</td> <td>會議室名稱</td> <td>會議名稱</td> <td>申請時間</td> <td>操做</td> </tr> <tr> <td class="meetingNotifyOneWeekId">1</td> <td class="meetingNotifyOneWeekRoom">會議室(918)</td> <td >共同探討黨的18大會議精神1</td> <td>2014-03-12 10:20-11:20</td> <td> <span> <input type="button" class="btnModify" value="變動" /> </span> <span> <input type="button" class="btnCancel2" value="撤銷" /> </span> </td> </tr> <tr> <td class="meetingNotifyOneWeekId">1</td> <td class="meetingNotifyOneWeekRoom">會議室(918)</td> <td >共同探討黨的18大會議精神1</td> <td>2014-03-12 10:20-11:20</td> <td> <span><input type="button" class="btnModify" value="變動" /></span> <span><input type="button" class="btnCancel2" value="撤銷" /></span> </td> </tr> </table> </div> <div class="InRight1">共有3個會議<span><</span><span>1</span><span>></span></div> </div> </div> </div> </body> <script src="commom_shenergy.js"></script> </asp:content>
通常處理程序 css
<%@ WebHandler Language="C#" Class="HandlerMeetReq" %> <%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %> <%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %> using System; using System.Web; using Microsoft.SharePoint; using CodeArt.SharePoint.CamlQuery; using EntityLib; public class HandlerMeetReq : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; MeetEntity meetingEntity = new MeetEntity(); try { string strReq = context.Request["req"]; string strMethod = context.Request["method"]; MeetEntity entity = Newtonsoft.Json.JsonConvert.DeserializeObject<MeetEntity>(strReq); SPContext.Current.Web.AllowUnsafeUpdates = true; SPList list = SPContext.Current.Web.Lists["會議申請"]; SPListItem item = null; if (strMethod == "Add") { item = list.AddItem(); } else { item = list.GetItemById(int.Parse(entity.MeetId)); } if (strMethod == "Add" || strMethod == "Update") { item["標題"] = entity.MeetTitle; item.Update(); } else if (strMethod == "Del") { item.Delete(); } context.Response.Write("OK"); } catch (Exception ex) { context.Response.Write(ex.Message); } } public bool IsReusable { get { return false; } } } //public class MeetEntity //{ // public MeetEntity() // { // } // public string MeetId; // public string MeetTitle; // public string MeetRoomId; // public string MeetRoomTitle; // public string MeetContent; //}
查看數據頁面 :http://tuvaudit:41182/Lists/List/AllItems.aspx前端
<%@ WebHandler Language="C#" Class="HandlerMeetList" %> <%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %> <%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %> <%@ Assembly Name="EntityLib, Version=1.0.0.0, Culture=neutral" %> using System; using System.Web; using System.Collections.Generic; using Microsoft.SharePoint; using CodeArt.SharePoint.CamlQuery; using EntityLib; public class HandlerMeetList : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; SPList list = SPContext.Current.Web.Lists["會議申請"]; QueryField qfId = new QueryField("ID"); SPListItemCollection items = ListQuery.From(list).Where(qfId > 0).GetItems(); List<MeetEntity> lstEntities = new List<MeetEntity>(); foreach (SPListItem item in items) { MeetEntity entity = new MeetEntity(); entity.MeetId = item.ID.ToString(); entity.MeetTitle = ConvertObj(item["序列號"]); entity.MeetRoomId = ConvertObj(item["會議室名稱"]); entity.MeetRoomTitle = ConvertObj(item["會議名稱"]); entity.MeetContent = ConvertObj(item["申請時間"]); lstEntities.Add(entity); } //context.Response.Write("Hello World"); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(lstEntities)); } public bool IsReusable { get { return false; } } private string ConvertObj(object obj) { return obj == null ? "" : obj.ToString(); } } //public class MeetEntity //{ // public MeetEntity() // { // } // public string MeetId; // public string MeetTitle; // public string MeetRoomId; // public string MeetRoomTitle; // public string MeetContent; //}
<script type="text/javascript"> //$.ajax({ // url: "./Handler/HandlerMeetList.ashx",//查詢 // type: "post", // async: false, // dataType: "json", // data: { // }, // success: function (arr) { // for (var i = 0; i < arr.length; i++) { // var en = arr[i]; // alert(en.MeetTitle); // } // }, // error: function (XMLHttpRequest, textStatus, errorThrown) { // alert('錯誤!'); // } //}); //$("#MeetingAdd").bind("click", Add); $("#MeetingQuery").bind("click", Query); function Query() { alert("查詢:"); $.ajax({ url: "./Handler/HandlerMeetList.ashx",//查詢 type: "post", async: false, dataType: "json", data: { }, success: function (arr) { for (var i = 0; i < arr.length; i++) { var en = arr[i]; alert("序列號:"+en.MeetingId +"會議室名:"+en.MeetingRoomName); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } function Save() { var entity = {}; entity.MeetId = 1; entity.MeetTitle = "bbbb"; $.ajax({ url: "./Handler/HandlerMeetReq.ashx",//查詢 type: "post", async: false, dataType: "text", data: { method: "ADD", req: JSON.stringify(entity) }, success: function (arr) { alert(arr); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } function Add() { alert("增長") var MeetingApply = {}; MeetingApply.MeetingId = 1; MeetingApply.MeetingRoomName = "會議室(918)"; MeetingApply.MeetingName = "共同探討黨的18大"; MeetingApply.MeetingName = "共同探討黨的18大"; MeetingApply.MeetingApplyTime = "2016-11-14 12:10" entity. $.ajax({ url: "./Handler/HandlerMeetReq.ashx",//查詢 type: "post", async: false, dataType: "text", data: { method: "Add", req: JSON.stringify(entity) }, success: function (arr) { alert(arr); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } function Del() { var entity = {}; entity.MeetId = 1; entity.MeetTitle = "bbbb"; $.ajax({ url: "./Handler/HandlerMeetReq.ashx",//查詢 type: "post", async: false, dataType: "text", data: { method: "Del", req: JSON.stringify(entity) }, success: function (arr) { alert(arr); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('錯誤!'); } }); } </script>