2014-06-30 26 views
1

嗨,我正在研究一個應用程序,它在服務器上顯示動態生成的圖像。爲了獲取圖像,在我們的例子中,應用程序使用Ajax請求。檢索到的數據是這樣的:從ajax請求的Extjs圖像/ png

"�PNG 


    IHDRLXx�s 
    sBIT|d� pHYsaa�?�i IDATx���w|U�����~�{BI(�H/�4AaeQQp�>�n�]Wݯ�"�W?~t���uuW]�""R)RBI ����w~�;)7 Iя�................................. 
..........................................." 

它看起來像this

在我的應用我有一個文本:圖像,我想要顯示的圖像,但我不知道該怎麼做。有誰知道如何?

這裏是ajax請求代碼。

Ext.Ajax.request({ 
url: 'http://localhost/my_url/you_dont_need_to_know_this', 
success: function(response){     
    //img.setData(response.responseText); //img is a Ext:image component. 
    debugger; 
}, 
scope: this 

});

+2

那麼你的Ajax請求的樣子..?你能告訴我們你的代碼嗎? –

回答

3

如果與圖像數據服務器responsds,做這樣的事情,

Ext.Ajax.request({ 
    binary: true, //set binary to true 
    url: 'http://localhost/my_url/you_dont_need_to_know_this', 
    success: function(response) { 
     var blob = new Blob([response.responseBytes], {type: 'image/png'}), 
     url = window.URL.createObjectURL(blob), 
     img = document.createElement('img'); 
     img.src = url; 

     //do something with img 
    } 
});