weixin_33743248 2015-02-04 11:40 采纳率: 0%
浏览 210

内容类型image / png ajax

My server request is returning image/png content type header. Server link is like this: http://locahost/PrintView?locate=12,12

My browser is showing image successful.

But I need to get image via ajax call. But ajax result is coming encoded format.

enter image description here

So I can not appent it to html img or another element.

    $.ajax({
        url: "http://localhost:7741/PrintView/Crop",
        type: "GET",
        crossDomain: true,
        data: { "locate":param },            
        success: function (response) {
           $('#crop').html('<img src="' + response + '" />');
           console.log(response)
        },
        error: function (xhr, status) {
            alert("error");
        }
    });
  • 写回答

2条回答 默认 最新

  • 7*4 2015-02-04 11:44
    关注

    You're trying to load an image from a GET request. There is absolutely no reason to complicate things by involving Ajax here.

    $('#crop').empty().append(
        $("<img />").attr(
            "src", 
            "http://localhost:7741/PrintView/Crop?locate=" + encodeURIComponent(param)
        )
    );
    
    评论

报告相同问题?