ajax請求aspx.cs後臺方法
阿新 • • 發佈:2018-11-17
前臺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); } }); }); });
後臺程式碼
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"; } }
執行結果