[英]server side c# method is not calling from ajax - asp.net
我正在尝试使用 ajax 调用 ac# 方法,如下所示。
<a href="#divrecentQ" id="linkdivrecentQ" onclick="lnkClick();" aria-controls="divrecentQ" role="tab" data-toggle="tab">Click here</a>
这是JS中的方法
function lnkClick() {
alert("called");
$.ajax({
type: "POST",
url: '/amain.aspx/LoadImages',
data: {},
success: function () {
alert(1);
},
dataType: 'html'
});
alert("cal");
}
服务器端:
public static void LoadImages()
{
log.Debug("LoadImages is called");
}
服务器端方法没有被调用。
有人可以帮忙吗?
谢谢
您应该定义静态方法并用[WebMethod]
属性包装它。
[WebMethod]
public static void LoadImages()
{
Label1.Text = "hi therre";
Response.Redirect("www.google.com");
log.Debug("LoadImages is called");
}
添加“contentType:”应用程序/json; charset=utf-8"," 在jquery中调用服务器端方法。
感谢大家的帮助。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.