前台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"; ???}}
运行结果
ajax请求aspx.cs后台方法
原文地址:https://www.cnblogs.com/yaotome/p/9975106.html