簡體   English   中英

無法通過異步Ajax調用呈現base64圖像返回

[英]Failing to render base64 image return by async ajax call

我試圖進行多個異步ajax調用,其中之一是從服務器請求base 64圖像。 如果我將base64圖像的ajax請求設置為同步,則它適用於IE,Chrome和Firefox。 但是,對於異步情況,圖像是每次都在IE中呈現,但不是偶爾在Chrome和Firefox中呈現。 有時正在渲染,有時卻沒有。 最重要的是,移動瀏覽器根本無法渲染圖像。

代碼很簡單,但是我不知道它怎么了。

 function TestViewModel() { var self = this; self.Image = ko.observable(); self.GetProfileData = function () { $.ajax({ async: true, type: 'GET', url: .., success: { // return profile data } }); } self.GetProfileImage = function() { $.ajax({ async: true, type: 'GET', url: .., success(data): { self.Image(data.Base64Image); } }); } self.GetProfileData(); self.GetProfileImage(); } ko.applyBindings(new TestViewModel()); 
 <img data-bind="attr: { src: Image }" alt="ProfileImage" /> 

我猜您應該使用內容類型前綴:

self.Image("data:image/x;base64," + data.Base64Image);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM