首页 > Web开发 > 详细

ajax请求aspx.cs后台方法

时间:2018-11-17 20:34:05      阅读:357      评论:0      收藏:0      [点我收藏+]

前台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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!