【发布时间】:2018-09-21 11:10:50
【问题描述】:
我正在尝试使用 jQuery 到 C# 方法进行 ajax 调用。
$(".imgDbAttachment").on("click", function (e) {
debugger;
var fileName = $(this).attr('data-attchment-id');
fileExt = $(this).attr('data-attchment-type');
loadAjaxImage(fileName, fileExt);
});
function loadAjaxImage(id,type) {
$.ajax({
type: "POST",
url: "../CommonDesign/Test.aspx/GetImage",
data:{
'attachmentId': id,
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
}
}).done(function (data) {
if (console && console.log) {
console.log(data);
}
});
}
public partial class Test: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var str = this.Request.Url;
}
[WebMethod]
public string GetImage(string attachmentId)
{
return "hello";
}
但是当我进行 ajax 调用时,控件正在点击 PageLoad() 而不是 GetImage() & 这反过来又返回整个 aspx 页面内容
检查这些链接,
但还是同样的问题。
任何建议/高度赞赏。
【问题讨论】:
标签: c# jquery asp.net ajax webmethod