首页 > Web开发 > 详细

JqueryAjax异步加载在ASP.NET

时间:2015-03-27 16:43:05      阅读:194      评论:0      收藏:0      [点我收藏+]

前台代码

<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();
        }

 

JqueryAjax异步加载在ASP.NET

原文:http://www.cnblogs.com/tangt/p/4371706.html

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