2012-08-10 275 views
2

我不知道它的可能与否,但我在我的服务器上有一个图像,我想通过$ .ajax函数下载并显示在我的jquery移动应用程序中。这里是我使用的代码:

$.ajax({ 
type: "GET", 
url: $url, 
dataType: "jpeg", 
async: true, 
timeout: 90000, 
success: function($data) 
    { 
console.log("success"); 

}, 
error: function() 
    { 
console.log("failure"); 
} 


}); 

我得到一个错误,不知道这是否是正确的做法

回答

0

它没有多大意义,下载与AJAX图像。你可能只需要设置的IMG elementsrc属性:

<div id="example">Example</div> 
<script> 
    var url = 'http://lorempixel.com/output/abstract-q-c-64-48-8.jpg'; // URL of the image 
    $('#example').click(function() { 
    $('<img>') // create a new image element 
     .attr('src', url) // set src 
     .appendTo(this); 
    }); 
</script>​ 

工作例如:http://jsfiddle.net/zrbRM/