如何从ajax.I调用非静态void函数出错。 这是Ajax代码: -如何通过ajax调用void非静态函数?
$('#button2 button').click(function() {
$.ajax({
type: "POST",
url: "practiced_final.aspx/display",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function()
{
},
error: function (a, b, c) {
alert(a + b + c);
}
})
return false;
});
这是C#方法代码:
[WebMethod]
protected void display()
{
HttpContext.Current.Response.Write("Hello");
}
这是错误信息: -
[object XMLHttpRequest]errorundefined
什么,我缺少什么?
请帮忙。
谢谢。
加属性到你的方法'display'' [Webmethod]'。我不确定您的这种方法是否应该公开 – harry180
我已经添加了它,但没有粘贴在这里。我仍然没有工作。 检查更新的代码。 – user1627138
看到这个[http://stackoverflow.com/questions/1360253/call-non-static-method-in-server-sideaspx-cs-from-client-side-use-javascript]相关问题哪个应该可以解决你的问题 –