<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryCSMethodForm.aspx.cs" Inherits="JQuerWeb.JqueryCSMethodForm" %>
CS代码:
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 JQuerWeb
{
public partial class JqueryCSMethodForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static String GetNowDate()
{
return "[{"nowtime":"" DateTime.Now.ToShortDateString() ""}]";
}
[WebMethod]
public static String GetOneDayLate(Int32 days)
{
return "[{"nowtime":"" DateTime.Now.AddDays(days).ToShortDateString() ""}]";
}
}
}
注意点:
(1) url的填写格式 url "/method name"
(2) contentType: "application/json; charset=utf-8", 这个必须要有
(3) 返回数据的类型为json
(4) data:"{days:1}",参数的传递
(5) 后台的方法必须是public static 而且还要有 [WebMethod]特性修饰