码迷,mamicode.com
首页 > Web开发 > 详细

ajax请求aspx.cs后台方法

时间:2018-11-17 21:00:56      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:ati   app   system   OLE   obj   color   oid   end   data   

前台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后台方法

标签:ati   app   system   OLE   obj   color   oid   end   data   

原文地址:https://www.cnblogs.com/yaotome/p/9975106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!