获取数据:图像/png;base64,{{图像}} net::ERR_INVALID_URL [英] GET data:image/png;base64,{{image}} net::ERR_INVALID_URL

查看:125
本文介绍了获取数据:图像/png;base64,{{图像}} net::ERR_INVALID_URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Angular.js(用于离子框架)转换从服务器获取的图像数据,我使用了以下代码:

I want to convert image data that I get from server using Angular.js (for use in ionic-framework), I have use this code :

$http.post(link, {
          token: token,
          reservationCode: reservationCode
          }).success(function (res){
            $scope.image = btoa(unescape(encodeURIComponent(res)));

        }).error(function (data) {
          return false;
        }); 

并在我的 html 中使用此代码:

And use this code in my html :

  <img src="data:image/png;base64,{{image}}">

但是这个错误总是显示:

But this error always show :

GET data:image/png;base64,{{image}} net::ERR_INVALID_URL

GET data:image/png;base64,{{image}} net::ERR_INVALID_URL

有人可以帮忙吗?

推荐答案

虽然回答晚了,但对未来的读者会有帮助:

Though a late answer, but will be helpful for future readers:

你应该做的是:

 <img ng-src="data:image/png;base64,{{image}}">

这意味着浏览器只会在加载数据时尝试访问它,并且会由 AngularJS 处理,因此您不会再收到该错误.

That would mean that the browser will try to access it only when the data is loaded and will be taken care by AngularJS and hence you will not get that error anymore.

这篇关于获取数据:图像/png;base64,{{图像}} net::ERR_INVALID_URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆