2012-08-10 134 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/