Front desk:
<%@ page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "Webapplication1.default"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script src= "Scripts/jquery-1.4.2.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ ("input[type= ' button '][value= ' Getonedaylater ']"). Click (function () {
$.ajax ({
Type: "Post",
URL: "Default.aspx/getonedaylate",
Data: "{days:1}",
DataType: "JSON",
ContentType: "Application/json; Charset=utf-8 ",
Success:function (data) {
$ ("Input#showtime"). Val (eval (' (' + DATA.D + ') ') [0].nowtime];
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
alert (Errorthrown);
}
});
});
});
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" value= "Getonedaylater"/>
<input type= "text" id= "ShowTime"/>
</div>
</form>
</body>
Background:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.Services;
Namespace WebApplication1
{
public partial class Default:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
[WebMethod]
public static String getonedaylate (Int32 days)
{
Return "[{\" nowtime\ ": \" "+ DateTime.Now.AddDays (days). ToShortDateString () + "\"}] ";
}
}
}
jquery calls the background method
jquery calls the background method