我需要进行 Ajax 调用以使用 C# 从服务器端获取图像源 ASP.NET
本文关键字:服务器端 获取 图像 NET ASP Ajax 调用 | 更新日期: 2023-09-27 18:36:39
我需要使用 ASP.NET C# 进行 Ajax 调用以从服务器端获取图像源。
我得到了下面的代码示例:
$('#popup-container').click(function() {
$.ajax({
type: "GET",
url: "img/popup_calculating.gif",
dataType: "image/gif",
success: function(img) {
i = new Image();
i.src = img;
$(this).append(i);
},
error: function(error, txtStatus) {
}
});
});
上面的代码想用 ASP.NET C#.aspx页面实现,但是我无法理解实现,从服务器调用图像,我的要求是像下面这样开发。
http://epaper.deccanchronicle.com/epaper_main.aspx#page986808
首先,$(this) 不是你认为的那样,因为它包含在不同的范围内($.ajax 请求的成功回调)。
$('#popup-container').click(function() {
var container = $(this);
$.ajax({
type: "GET",
url: "img/popup_calculating.gif",
dataType: "image/gif",
success: function(imgSrc) {
$(container).append('<img src="' + imgSrc + '" />);
},
error: function(error, txtStatus) {
}
});
});