ajax異步調用
阿新 • • 發佈:2017-06-04
article res req Language ted ren loaddata 信息 lsp
服務端aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RA_PublicityOnLineInfo.aspx.cs" Inherits="HMFW.Web.Pages.SQJS.ResidentsAutonomy.RA_PublicityOnLineInfo" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>網上公示信息管理</title> <script src="/Js/My97DatePicker/WdatePicker.js" type="text/javascript"></script> <script src="/Js/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="/Js/jquerytree/jquery.ztree.core-3.1.min.js" type="text/javascript"></script> <link href="/Js/jquerytree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" /> <script src="/Js/jquery.easyui.min.js" type="text/javascript"></script> <script src="/Js/jquery.validate.js" type="text/javascript"></script> <script src="/Js/jquery.form.js" type="text/javascript"></script> <link href="/themes/default/easyui.css" rel="stylesheet" type="text/css" /> <link href="/themes/icon.css" rel="stylesheet" type="text/css" /> <script src="/Js/jquery-loadmask-0.4/jquery.loadmask.min.js" type="text/javascript"></script> <link href="/Js/jquery-loadmask-0.4/jquery.loadmask.css" rel="stylesheet" type="text/css" /> <script src="/Js/edit.js" type="text/javascript"></script> <script src="/Js/Common.js" type="text/javascript"></script> <script src="/Js/Pages/SQJS/ResidentsAutonomy/RA_PublicityOnLineInfo.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <div> <table id="T_Content" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="content02"> <thead> <tr> <td colspan="4" class="content01bt"> <span runat="server" id="acTitle">公示信息</span>[<span runat="server" id="ActionInfo">新增</span>] </td> </tr> </thead> <tbody> <tr> <td nowrap="nowrap" width="13%" class="tdleft"> <span class="red">*</span>公示類別: </td> <td nowrap="nowrap" width="37%" class="tdright"> <asp:DropDownList ID="iTypeCode" runat="server" class="xlk180" ContentEditable="false"> <asp:ListItem Value="1">選舉通知</asp:ListItem> <asp:ListItem Value="2">選民登記通知</asp:ListItem> <asp:ListItem Value="3">初步候選人信息</asp:ListItem> <asp:ListItem Value="4">正式候選人信息</asp:ListItem> <asp:ListItem Value="5">正式選舉內容和時間</asp:ListItem> <asp:ListItem Value="6">選舉結果公示</asp:ListItem> </asp:DropDownList> <asp:HiddenField runat="server" ID="siTypeCode" /> </td> <td>是否公示:</td> <td> <asp:DropDownList ID="iOnLine" runat="server" class="xlk180" ContentEditable="false"> <asp:ListItem Value="1">是</asp:ListItem> <asp:ListItem Value="0">否</asp:ListItem> </asp:DropDownList></td> </tr> <tr> <td nowrap="nowrap" class="tdleft"><span class="red">*</span>公示時間: </td> <td align="left" colspan="3"> <asp:TextBox ID="txt_dPublictityStartTime" runat="server" onclick="WdatePicker()" class="srk80"></asp:TextBox>至<asp:TextBox ID="txt_dPublicityEndTime" runat="server" onclick="WdatePicker()" class="srk80"></asp:TextBox> <asp:HiddenField runat="server" ID="dPublictityStartTime" /> <asp:HiddenField runat="server" ID="dPublicityEndTime" /> </td> </tr> <tr> <td nowrap="nowrap" class="tdleft"> <span class="red">*</span>公示內容: </td> <td nowrap="nowrap" class="tdright" colspan="3"> <asp:TextBox ID="txt_sContent" runat="server" TextMode="MultiLine" class="Memo"></asp:TextBox> <asp:HiddenField runat="server" ID="sContent" /> </td> </tr> <tr> <td nowrap="nowrap" class="tdleft">備註: </td> <td nowrap="nowrap" class="tdright" colspan="3"> <asp:TextBox ID="txt_sMemo" runat="server" TextMode="MultiLine" class="Memo"></asp:TextBox> </td> </tr> </tbody> </table> <div class="tbError" id="LJRYerror"> </div> <table width="100%" height="36" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <xhm:xhmButtionEasyUI ID="btn_Save" runat="server" IconTypeSelected="save" OnClientClick="Save(false);return false">保存</xhm:xhmButtionEasyUI> <xhm:xhmButtionEasyUI ID="btn_SaveandAdd" runat="server" IconTypeSelected="save" OnClientClick="Save(true);return false;">保存並新增</xhm:xhmButtionEasyUI> <xhm:xhmButtionEasyUI ID="btn_Return" runat="server" IconTypeSelected="back" OnClientClick="NBack(infoflag);return false;">返回</xhm:xhmButtionEasyUI> </td> </tr> </table> </div> <input type="hidden" id="hidID" runat="server" /> </form> </body> </html>
前端javascript
var infoflag = true; //是否須要給父頁面賦值 True 彈出框口 須要 False 打開新頁面 不須要 var handleurl = "/Handle/SQJS/ResidentsAutonomy/RA_PublicityOnLine.ashx"; //一般處理程序路徑 //http://localhost:56248/Handle/SQJS/ResidentsAutonomy/RA_Candidate.ashx var candidateHandleUrl = "/Handle/SQJS/ResidentsAutonomy/RA_Candidate.ashx";//確定初步候選人和確定正式候選人 //http://localhost:56248/Handle/SQJS/ResidentsAutonomy/RA_ElectionProject.ashx var electionProjectHandleUrl = "/Handle/SQJS/ResidentsAutonomy/RA_ElectionProject.ashx";//確認正式選舉內容和時間和確認選舉結果 var type = getParameter("iType");//頁面狀態 編輯或者查看 $(function () { /******隱藏check 操作button*************/ if (type == "view") { $("#btn_Save").hide();//保存 $("#btn_SaveandAdd").hide();//保存並新增 infoflag = false;//用於查看界面 返回 $("#ActionInfo").text("查看"); //把標識設置為查看 $("#T_Content .red").css({ "display": "none" });//查看去除必填選項標識 $("#T_Content").find("input").attr("disabled", "disabled");//input $("#T_Content").find("textarea").attr("disabled", "disabled");//textarea $("#iTypeCode").attr("disabled", "disabled");//公示類別 $("#iOnLine").attr("disabled", "disabled");//是否公示 } var ID = GetID(); if (ID != "") { Load(ID); } $("#iTypeCode").change(function () { var checkValue = $("#iTypeCode").val(); var ID = GetID();//網上公示ID var gProjectID = getParameter("gProjectID");//選舉項目ID if (ID == "") {//相關公式信息表:RA_Candidate RA_ElectionProject View_SQ_RA_ElectionProject_sPreliminaryConfirm View_SQ_RA_ElectionProject_sFormallyConfirm switch (checkValue) { case "3"://確定初步候選人【正式確覺得1】 clearFields1(); $.ajax({ type: "POST", //用POST方式傳輸 dataType: "json", //數據格式:JSON url: handleurl, //目標地址 data: "action=preliminary&gID=" + gProjectID, cache: false, success: function (data) { //數據獲取完成,填充頁面據顯示 if (data != null && data != "") { LoadData1(data); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, errorThrown, ‘error‘); }, beforeSend: function () { }, complete: function () { $("hidLoad").val("1"); } }); break; case "4": clearFields1(); $.ajax({ type: "POST", //用POST方式傳輸 dataType: "json", //數據格式:JSON url: handleurl, //目標地址 data: "action=formally&gID=" + gProjectID, cache: false, success: function (data) { //數據獲取完成,填充頁面據顯示 if (data != null && data != "") { LoadData1(data); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, errorThrown, ‘error‘); }, beforeSend: function () { }, complete: function () { $("hidLoad").val("1"); } }); break; case "5": clearFields2(); $.ajax({ type: "POST", //用POST方式傳輸 dataType: "json", //數據格式:JSON url: electionProjectHandleUrl, //目標地址 data: "action=get&gID=" + gProjectID, cache: false, success: function (data) { //數據獲取完成,填充頁面據顯示 if (data != null && data != "") { $("#txt_dPublictityStartTime").val(renderTime(data.dStartDate, true));//開始時間dPublictityStartTime $("#txt_dPublicityEndTime").val(renderTime(data.dEndDate, true));//結束時間 $("#txt_sContent").val(data.sProjectContent);//公示內容 $("#dPublictityStartTime").val(renderTime(data.dStartDate, true));//公示開始時間 $("#dPublicityEndTime").val(renderTime(data.dEndDate, true));//公示結束時間 $("#sContent").val(data.sProjectContent);//公示內容 //$("#txt_sMemo").val(data.sMemo);//備註 } }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, errorThrown, ‘error‘); }, beforeSend: function () { }, complete: function () { $("hidLoad").val("1"); } }); break; case "6": clearFields2(); $.ajax({ type: "POST", //用POST方式傳輸 dataType: "json", //數據格式:JSON url: handleurl, //目標地址 data: "action=getivotecount&gID=" + gProjectID, cache: false, success: function (data) { //數據獲取完成,填充頁面據顯示 if (data != null && data != "") { $("#txt_dPublictityStartTime").val(renderTime(data.dStartDate, true));//開始時間dPublictityStartTime $("#txt_dPublicityEndTime").val(renderTime(data.dEndDate, true));//結束時間 $("#txt_sContent").val(data.iVoteCount);//公示內容:現場選舉 網上選舉 結果匯總 $("#dPublictityStartTime").val(renderTime(data.dStartDate, true));//公示開始時間 $("#dPublicityEndTime").val(renderTime(data.dEndDate, true));//公示結束時間 $("#sContent").val(data.iVoteCount);//公示內容 //$("#txt_sMemo").val(data.sMemo);//備註 } }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, errorThrown, ‘error‘); }, beforeSend: function () { }, complete: function () { $("hidLoad").val("1"); } }); break; default: clearFields3(); break; } } else if (ID != "") {//RA_PublicityOnLine表 Load(ID); } }); }); function Load(ID) { $.ajax({ type: "POST", //用POST方式傳輸 dataType: "json", //數據格式:JSON url: handleurl, //目標地址 data: "action=get&gID=" + ID, cache: false, success: function (data) { //數據獲取完成,填充頁面據顯示 if (data != null && data != "") { LoadData(data); IsPublicityOnLine(data);//頁面載入 設置屬性值 } }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, errorThrown, ‘error‘); }, beforeSend: function () { }, complete: function () { $("hidLoad").val("1"); } }); } function IsPublicityOnLine(data) { $("#iTypeCode").attr("disabled", "disabled"); var iTypeCode = data.iTypeCode; switch (iTypeCode) { case 3: $("#txt_sContent").attr("disabled", "disabled");//正式選舉內容 break; case 4: $("#txt_sContent").attr("disabled", "disabled");//正式選舉內容 break; case 5: clearFields2(); case 6: clearFields2(); break; default: break; } } function LoadData(data) { SetInputValue(data); $("#txt_dPublictityStartTime").val(renderTime(data.dPublictityStartTime, true));//公示開始時間 $("#txt_dPublicityEndTime").val(renderTime(data.dPublicityEndTime, true));//公示結束時間 $("#dPublicityEndTime").val(renderTime(data.dPublicityEndTime, true));//公示結束時間 $("#dPublictityStartTime").val(renderTime(data.dPublictityStartTime, true));//公示開始時間 $("#sContent").val(data.sContent); $("#siTypeCode").val(data.iTypeCode); } function LoadData1(data) { $("#txt_sContent").val(data.sCandidatePeopNames);//公示內容 $("#sContent").val(data.sCandidatePeopNames);//公示內容 //$("#txt_sMemo").val(data.sMemo);//備註 } function CheckInput() { var result = $("#form1").validate({ rules: { txt_dPublictityStartTime: { required: true, dateISO: true }, txt_dPublicityEndTime: { required: true, dateISO: true }, txt_sContent: { required: true, maxlength: 500 } } }); return result.form(); }; function CheckInput1(iTypeCode) { var result; if (GetID() == "") { var gProjectID = getParameter("gProjectID");//選舉項目ID $.ajax({ type: "POST", url: handleurl, data: "action=ismanypublicityonline&gProjectID=" + gProjectID + "&iCode=" + iTypeCode, dataType: "json", async: false, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert(‘錯誤‘, XmlHttpRequest.responseText, ‘error‘); }, success: function (returnJsonValue) { if (returnJsonValue.result == false) { $.messager.alert(‘信息‘, returnJsonValue.data, ‘info‘); result = returnJsonValue.result.toString(); } //clearFields(); //清空界面和隱藏域ID }, beforeSend: function () { }, complete: function () { } }); } return result; } function Save(isDoNew) { var iTypeCode = $("#iTypeCode").val();//網上公示類型 var action = "add"; var queryString = $(‘#T_Content :input‘).fieldSerialize(); if (GetID() != "") { action = "edit"; iTypeCode = $("#siTypeCode").val(); } var sTypeName = "";//公示類別 if (iTypeCode != "") {//公示類別 sTypeName = $("#iTypeCode").find("option:selected").text(); } queryString += "&sTypeName=" + sTypeName; if (CheckInput1(iTypeCode) == "false") {//先驗證同一個項目不同意有多個同樣類別公式! 後驗證基礎信息 return false; } var data = "action=" + action + "&gID=" + GetID() + "&" + queryString + "&gProjectID=" + getParameter("gProjectID"); // Save_1(isDoNew, handleurl, data, infoflag); } function clearFields2() { //////////////$("#txt_dPublictityStartTime").attr("disabled", "disabled");//開始時間 //////////////$("#txt_dPublicityEndTime").attr("disabled", "disabled");//結束時間 $("#txt_sContent").attr("disabled", "disabled");//正式選舉內容 } //設置界面屬性值 確定正式選舉內容和時間 function clearFields1() { //////////$("#txt_dPublictityStartTime").attr("disabled", false);//開始時間 //////////$("#txt_dPublicityEndTime").attr("disabled", false);//結束時間 $("#txt_sContent").attr("disabled", "disabled"); } function clearFields3() { $("#iTypeCode").attr("disabled", false);// //////////$("#txt_dPublictityStartTime").attr("disabled", false);// //////////$("#txt_dPublicityEndTime").attr("disabled", false);// $("#txt_sContent").attr("disabled", false);//正式選舉內容 SetID(""); //清空ID的隱藏域 $("#txt_dPublictityStartTime").val(""); $("#txt_dPublicityEndTime").val(""); $("#sContent").val(""); $("#txt_sContent").val(""); $("#txt_sMemo").val(""); $("#iOnLine").val("1"); } function clearFields() { $("#iTypeCode").attr("disabled", false);// ////////$("#txt_dPublictityStartTime").attr("disabled", false);// ////////$("#txt_dPublicityEndTime").attr("disabled", false);// $("#txt_sContent").attr("disabled", false);//正式選舉內容 SetID(""); //清空ID的隱藏域 $(‘#T_Content :input‘).clearFields(); //清空界面 $("#sContent").val(""); //$("#siTypeCode").val(""); $("#iTypeCode").val("1"); $("#iOnLine").val("1"); }
ajax異步調用