Load image with ajax (jQuery)

  • 1 Replies
  • 1192 Views
Load image with ajax (jQuery)
« on: May 04, 2016, 19:44:30 pm »
I need to make an image load with ajax call:

Code
$.ajax({
    type: "GET",
    url: url,
    dataType: "jsonp",
    jsonp : "onJSONPLoad",
    jsonpCallback: "imgCallback",
    crossDomain: "true",
    success: function(res) {
        console.log("Success");
    },
    error: function (xhr, status) {
        console.log('error: ' + status);
    }   
});

How can I achieve this ?

*

Ruhit

  • *
  • 22
Re: Load image with ajax (jQuery)
« Reply #1 on: May 08, 2016, 18:04:02 pm »
Code
<div id="imageLoader" style="display: none">
<img src="" />
</div>

<script>
$(function() {

    $('#imageLoader').show();

    $.ajax({
        type: "GET",
        url: surl,
        dataType: "jsonp",
        cache : false,
        jsonp : "onJSONPLoad",
        jsonpCallback: "newarticlescallback",
        crossDomain: "true",
        success: function(response) {
            $("#imageLoader").hide();
            console.log("Successfully loaded image");
        },
        error: function (xhr, status) { 
            $("#imageLoader").hide();
            alert('unable to load: ' + status);
        }
    }); 
});
</script>

 

Sitemap 1 2 3 4 5 6 7 8