zoukankan      html  css  js  c++  java
  • jQuery AJAX实现调用页面后台方法

    <script type="text/javascript">
    function doSend() {
    $.ajax({
         type: "post",
         url: "aaa.aspx/SendMes",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {

        //返回的数据用data.d获取内容
        alert(data.d);
       }
    });
    }
    </script>

    后台

    [WebMethod] 
    public static string SendMes() 

    return "Hello Ajax!"; 
    }

    有参数

    $(function() { 
    $("#btnOK").click(function() { 
    $.ajax({ 
    type: "Post", 
    url: "demo.aspx/GetStr", 
    //方法传参的写法一定要对,str为形参的名字,str2为第二个形参的名字 
    data: "{'str':'我是','str2':'XXX'}", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function(data) { 
    //返回的数据用data.d获取内容 
    alert(data.d); 
    }, 
    error: function(err) { 
    alert(err); 

    }); 

    //禁用按钮的提交 
    return false; 
    }); 
    });

    [WebMethod] 
    public static string GetStr(string str, string str2) 

    return str + str2; 
    }

  • 相关阅读:
    P4630-[APIO2018]Duathlon铁人两项【圆方树】
    P4980-[模板]Pólya定理
    bzoj4589-Hard Nim【FWT】
    CF700E-Cool Slogans【SAM,线段树合并,dp】
    sqrt数据结构
    NOIP历年好题
    ACM题解吖
    [ZJOI2010]排列计数
    [CQOI2014]数三角形
    [SHOI2007]书柜的尺寸
  • 原文地址:https://www.cnblogs.com/codeloves/p/2961004.html
Copyright © 2011-2022 走看看