2014-10-30 37 views
0

我使用的是URL,這樣如何將圖像文件加載到JQuery中?

var imgPaht = user.get("ProfilePic"); 

    $('<img src="' + imgPaht + '">').load(function() { 
     $(this).width(400).height(400).appendTo('#profile_pic'); 
    }) 

現在解析檢索從解析圖像,圖像不保持作爲一個字符串,它保存爲文件。如何更改上面的行來處理文件而不是url。

我已經試過

var profilePhoto = profile.get("ProfilePic"); 
$("profileImg")[0].src = profilePhoto.url(); 

Parse backend
錯誤我得到 enter image description here

+0

這可能是在這裏回答:http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri但不使用/需要jQuery,只是普通JS。 – 2014-10-30 18:06:14

+0

當你說「文件」是它Base64作爲答案嗎?或其他? – 2014-10-30 18:31:41

+0

@ RokoC.Buljan我檢查過,它肯定是一個對象... – Dano007 2014-10-30 20:17:38

回答

0

編碼的圖像文件中的數據不會直接插入到一個img標籤src財產。必須先將其解碼爲原始圖像數據,然後將其分配給以data:爲前綴的src屬性。

有關如何操作的更多信息,請參閱Using raw image data from ajax request for data URI

相關問題