AJAX返回链接而不是图像


AJAX returning link not 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>

返回文本而不是图像:

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

Replace

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

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

它会工作的很好。text()输出字符串,html()输出html标记

尝试:

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

Text用于在元素中注入一个文本节点,该节点不被解释为html。html()方法将html写入元素,并按此解释。