Page Method(使用jQuery调用)返回页面的全部内容,而不返回method的值.
问题描述:
您好,我们正在使用jquery发送ajax请求,但每次都会返回其页面的内容.
我们正在使用此代码.
使用.NET Framework版本2的服务器
Hi we are using jquery to sending ajax requests but its returns page''s content everytime.
we are using this code.
Server using .NET Framework version 2
$.ajax({
type: "POST",
url: "ajaxPage.aspx/testMethod",
data: "{test:'test'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$("#span_result").html(result.d).fadeIn();
},
error: function (msg) {
$("#span_result").hide();
}
});
//ajaxPage.aspx.cs
[System.Web.Services.WebMethod]
public static string testMethod(string test)
{
return test;
}
答
.ajax({ 类型:" , 网址:" , 数据:" , contentType:" , dataType:" , 成功:功能(结果){
.ajax({ type: "POST", url: "ajaxPage.aspx/testMethod", data: "{test:'test'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) {
(" #span_result").html(result.d).fadeIn(); }, 错误:函数(msg){
("#span_result").html(result.d).fadeIn(); }, error: function (msg) {
(" #span_result").hide(); } });
("#span_result").hide(); } });
//ajaxPage.aspx.cs
[System.Web.Services.WebMethod]
public static string testMethod(string test)
{
return test;
}