ajax請求aspx.cs後臺方法

前臺jquery代碼jquery

$(function () { $("#btnfix").click(function () { $.ajax({ type: "post", url: "fix.aspx/test", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { console.log(data.d); }, error: function (err) { alert(err); } }); }); });

後臺代碼ajax

using System.Web.Services; //引用Web.Services命名空間

public partial class Fix : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] //添加Attribute
    public static string test()   //方法設爲靜態
 { return "hello world"; } }

運行結果json

相關文章
相關標籤/搜索