-2

Im getting link instead of image.

    $.ajax({
    type: "GET",
    url: "image.php",
    contentType: "image/png",
    success: function(result){
        $('.image').text(result);
    }
});

$image = "http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png";
echo '<img src="'.$image.'"></img>';

<div class="image"></div>

Returns text instead of image:

<img src="http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png"></img>
Arnas Marnas
  • 43
  • 1
  • 1
  • 6
  • possible duplicate of [Can jquery .ajax load image?](http://stackoverflow.com/questions/4285042/can-jquery-ajax-load-image) – Jay Blanchard Jul 29 '15 at 15:42
  • Im using UTF-8 encoding – Arnas Marnas Jul 29 '15 at 15:42
  • I dont think it could work, Im taking info from mysql and then refreshing image with AJAX. – Arnas Marnas Jul 29 '15 at 15:45
  • I am not sure if you're using the `` tag correctly. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img – Maximus2012 Jul 29 '15 at 15:50
  • Check the resultant source after the ajax call runs ... you are putting the image as the src attribute of the element... not the path to the image as is required – Orangepill Jul 29 '15 at 16:09
  • It would be possible to convert the image data that you are getting from the request and converting it to a data url that can be used as the image source as is shown [here](http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri) – Orangepill Jul 29 '15 at 16:12

2 Answers2

0

Replace

$('.image').text(result);

with

$('.image').html(result);

It will work fine. text() outputs string and html() outputs html markup

Crunch Much
  • 1,537
  • 1
  • 11
  • 14
0

Try:

$.ajax({
    type: "GET",
    url: "image.php",
    contentType: "image/png",
    success: function(result){
        $('.image').html(result); //change text to html
    }
});

Text is used to inject a text node into the element, which isn't interpreted as html. The html() method writes html into the element and is interpreted as such.

Evadecaptcha
  • 1,403
  • 11
  • 17