1

想象一下,我想从以下位置获取图像:

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, '&lt;');
        data = data.replace(/>/g, '&gt;');
        $('#file_content').html('<pre>' + data + '</pre>');    
    },
    error: function(a,b,c){
        alert("There has been an error! Try again...");
    } 
});      

我猜是这样的?

4

1 回答 1

3

您不需要 ajax,使用 javascript,您可以简单地设置 SRC 属性值。

$(function(){
   $("#img1").attr(
      "src","http://www.entheosweb.com/fireworks/images/tracing/img18.jpg") 

});​

示例:http: //jsfiddle.net/PBKpk/1/

于 2012-05-16T18:59:26.243 回答