第一种就是对应方法的请求 虽然对应方法 但还是会刷新页面 webform是基于事件的 每次请求都会出发pageload
<script> $(function () { $("#btn").click(function () { $.ajax({ type: "POST", contentType: "application/json", url: "Index.aspx/SayHello", data: null, dataType: "json", success: function (msg) { alert(msg.d); } }); }); }); </script>
[System.Web.Services.WebMethod] public static string SayHello() { return "Hello"; }
第二种方法 就是直接请求 pageload
protected void Page_Load(object sender, EventArgs e)
{
_delWhere = "";
if (Request["where"] != null)
{
_where = Request["where"].ToString();
BindData(_where);
}
}
$.ajax({
url: "BugListnew.aspx?where=" + where,
type: "Post",
dataType: "json", //请求到服务器返回的数据类型
data: { "where": where },
success: function(data) {
var obj = $.parseJSON(data); //这个数据
var name = obj.Json[0].UserName;
var age = obj.Json[0].Age;
document.getElementById("name").innerHTML = name;
document.getElementById("age").innerHTML = age;
}
})