首页 > 代码库 > asp.net ajax

asp.net ajax

<script src="http://www.mamicode.com/Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
    function test() {
        $.ajax({
            async:true,
            type: "post",
            url: "default.aspx/hello",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $("#msg").css("color", "#0000FF").html(data.d);
            },
            error: function (err) {
                $("#msg").css("color", "#FF0000").html("access faield:" + err);
            }
        });
        return false;
    }
</script>


<input type="button" value="http://www.mamicode.com/确定" onclick="javascript:test();" />
<button onclick="javascript:test();return false;">确定2</button>
<div id="msg">测试</div>

button 类型的后面必须加javascript:test();return false;否则页面依然刷新

 

asp.net ajax