我在 jquery 中发出一个 ajax 请求,如下所示。此 ajax 请求动态获取图像。根据 num
$.ajax({
type: "POST",
url: "ABC.php?num=1",
success: function(response) {
if(response == 1) {
//some code
}
else {
// Here I am not able to set image content.
$("#image").attr("src", "data:image/png;base64,' + response + '");
}
}
});
有没有办法使用 ajax 请求的响应来设置图像内容。谢谢。
最佳答案
那里有一些不需要的单引号。使用这个:
$("#image").attr("src", "data:image/png;base64," + response);
关于javascript - 从 ajax 响应设置图像内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20468954/