[英]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.