我只是想知道的是,反正是有使用jQuery("$阿贾克斯"),使局部呈现而不使用.NET Ajax框架(无脚本管理器),使Ajax请求.
我之前尝试过这个,但它page_load每次都在执行,而没有达到页面方法.
function doAsync()
{
jQuery.ajax({
type: "POST",
url: "/WebForm1.aspx/testMethod",
error: function (xhr, status, error) { alert(status); },
success: function (response) { alert('suc'); }
)};
}
[WebMethod]
public static void testMethod()
{
//server side code
}
Run Code Online (Sandbox Code Playgroud)
这里有什么不对吗?
谢谢!
Dav*_*ard 15
你缺少的是内容类型.要向页面方法发出请求,您必须完全按照以下方式拨打电话:
$.ajax({
type: "POST",
url: "/WebForm1.aspx/testMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅此处:http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
| 归档时间: |
|
| 查看次数: |
2733 次 |
| 最近记录: |