Javascript 使用jquery从html页面调用ASP页面方法
我有一个静态HTMl页面index.HTMl,其中包含用于获取数据的文本框 我想使用jquery/AJAX将此数据发布到ASP页面Default.aspx 我试过这个Javascript 使用jquery从html页面调用ASP页面方法,javascript,jquery,asp.net,ajax,Javascript,Jquery,Asp.net,Ajax,我有一个静态HTMl页面index.HTMl,其中包含用于获取数据的文本框 我想使用jquery/AJAX将此数据发布到ASP页面Default.aspx 我试过这个 $.ajax({ url: "Default.aspx/GetCurrentTime", type: "post", dataType: "json", contentType: "application/json; charset=
$.ajax({
url: "Default.aspx/GetCurrentTime",
type: "post",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: {},
success: function (data2) {
alert("success::");
},
error: function (response) {
alert("ERROR:::" + response.d);
}
});
但这显示了未定义的错误
请帮我解决这个问题。您需要在页面方法上使用
[WebMethod]
属性
[WebMethod]
public static string GetCurrentTime()
{
...
}
是的,我做了[System.Web.Services.WebMethod]公共静态字符串GetCurrentTime(){}@user1491927将函数放入您的问题中