假设我想从以下位置获取图像:
http://www.entheosweb.com/fireworks/images/tracing/img18.jpg
使用 jquery ajax。
我该如何去做。
$.ajax({
url: 'http://www.entheosweb.com/fireworks/images/tracing/img18.jpg',
type: "POST",
dataType: "image",
async: true,
success: function(data) {
data = data.replace(/</g, '<');
data = data.replace(/>/g, '>');
$('#file_content').html('<pre>' + data + '</pre>');
},
error: function(a,b,c){
alert("There has been an error! Try again...");
}
});
我猜是这样的?
最佳答案
您不需要ajax,使用javascript,您可以简单地设置SRC属性值。
$(function(){
$("#img1").attr(
"src","http://www.entheosweb.com/fireworks/images/tracing/img18.jpg")
});
关于jquery - 使用 ajax 从图像文件的直接 url 接收图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10624816/