• JqueryAjax异步加载在ASP.NET


    前台代码

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function ShowCurrentTime() {
            $.ajax({
                url: "webService.aspx/GetCurrentTime",//请求的页面/页面处理数据的方法
                type: "POST",                            //传输方式
                contentType: "application/json;charset=utf-8", //编码
                dataType: "json",                             //格式
                data: '{name: "' + $("input[name='name']").val() + '" ,age:"' + $("input[name='age']").val() + '"}',//json字符串
                success: function (data) {                        //成功以后的回调函数
                    alert(data.d);
                },
                failure: function (data) {
                    alert(data.d);
                }
            })
        }
    </script>
    <body>
        <form id="form1" runat="server">
        <div>
        <input type="text" name="name" />
        <input type="text" name="age" />
        <input type="button" value="获取当前时间" onclick="ShowCurrentTime()" />
        </div>
        </form>

    webService.aspx后台代码:

    [System.Web.Services.WebMethod]                      //将 WebMethod 属性附加到 Public 方法表示希望将该方法公开为 XML Web services 的一部分
            public static string GetCurrentTime(string name,string age)
            {
                return "Hello"+name+age+DateTime.Now.ToString();
            }
  • 相关阅读:
    五、excel末尾补0和开头补0
    MYSQL查询前30条数据
    MYSQL数据库从A表把数据插入B表
    测试用例大全
    EXTJS 5.0 资料
    fs event_socket
    centos 编译swoole
    Valgrind简单用法
    linux 大并发下 内核优化
    FS拓展设置
  • 原文地址:https://www.cnblogs.com/tangt/p/4371706.html
Copyright © 2020-2023  润新知