Jquery mobile 通过$.ajax下载和使用图像

Jquery mobile 通过$.ajax下载和使用图像,jquery-mobile,Jquery Mobile,我不知道这是否可能,但我的服务器上有一个图像,我想通过$.ajax函数下载并显示在我的jquery移动应用程序中。下面是我使用的代码: $.ajax({ type: "GET", url: $url, dataType: "jpeg", async: true, timeout: 90000, success: function($data) { console.log("success"); }, error: function() { console.log("fai

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

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

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


});

我遇到一个错误,不确定这是否是正确的方法

使用AJAX下载图像没有多大意义。您可能只需要设置ìmg元素的src属性:


工作示例:

使用AJAX下载图像没有多大意义。您可能只需要设置ìmg元素的src属性:

工作示例:

<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>​