<div class="codetitle"> <span><a style="CURSOR: pointer" data="32917" class="copybut" id="copybut32917" onclick="doCopy('code32917')"><u>复代码码</u></a></span> 代码如下:</div> <div class="codebody" id="code32917"> <br><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryCSMethodForm.aspx.cs" Inherits="JQuerWeb.JqueryCSMethodForm" %> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><html xmlns="http://www.w3.org/1999/xhtml" > <br><head runat="server"> <br><제목></제목> <br><script type="text/javascript" src="JS/jquery-1.4.2.js"></script> <br><script type="text/javascript"> <br>$(document).ready(function() { <br>$("input[type='button'][value='GetDate']").click(function() { <br>$.ajax ({ <br>유형: "post", <br>url: "JqueryCSMethodForm.aspx/GetNowDate", <br>datatype: "json", <br>contentType: "application/json; charset=utf-8", <br>성공: function(data) { <br>$("input#showTime").val(eval('(' data.d ')')[0].nowtime) <br>}, <br>error: function(XMLHttpRequest, textStatus, errorThrown) { <br>alert(errorThrown); <br>} <br>}) <br>$("input[type='button'] [value='GetOneDayLater']").click(function() { <br>$.ajax({ <br>type: "post", <br>url: "JqueryCSMethodForm.aspx/GetOneDayLate", <br>data :"{days:1}", <br>데이터 유형: "json", <br>contentType: "application/json; charset=utf-8", <br>성공: function(data) { <br>$( "input#showTime").val(eval('(' data.d ')')[0].nowtime) <br>}, <br>error: function(XMLHttpRequest, textStatus, errorThrown) { <br> 경고(오류 발생) <br>} <br>}) <br>}); <br></script> <br></head> <br><본문> <br><form id="form1" runat="server"> <br><div> <br><input type="button" value="GetDate" /> <br><입력 유형=버튼 값="GetOneDayLater" /> <br><input type="text" id="showTime" /> <br></div> <br></form> <br></body> <br></html> <br><br> <br>CS代码: </div> <br><br><div class="codetitle"> <span>复主代码<a style="CURSOR: pointer" data="24631" class="copybut" id="copybut24631" onclick="doCopy('code24631')"><u></u> 代码如下:</a></span> </div> 시스템 사용; <div class="codebody" id="code24631">System.Collections.Generic 사용; <br>System.Linq 사용; <br>System.Web 사용; <br>System.Web.UI 사용; <br>System.Web.UI.WebControls 사용; <br>System.Web.Services 사용; <br>네임스페이스 JQuerWeb <br>{ <br>공용 부분 클래스 JqueryCSMethodForm : System.Web.UI.Page <br>{ <br>protected void Page_Load(객체 전송자, EventArgs e) <br>{ <br>} <br>[WebMethod] <br>public static String GetNowDate() <br>{ <br>return "[{"nowtime":"" DateTime.Now.ToShortDateString() ""}]"; <br>} <br>[WebMethod] <br>public static String GetOneDayLate(Int32일) <br>{ <br>return "[{"nowtime":"" DateTime.Now.AddDays(days).ToShortDateString() ""}]"; <br>} <br>} <br>} <br><br> <br>注意点: </div>(1) url적填写格式 url "/method name" <br>(2) contentType: "application /json; charset=utf-8", 这个必须要유 <br>(3) 返回数据的类型为json <br>(4) data:"{days:1}",参数的传递 <br>(5 ) 后台적 방법법必须是public static 而且还要有 [WebMethod]특수성修饰