【问题标题】:Angular not loading images and content for some browsersAngular 不为某些浏览器加载图像和内容
【发布时间】:2016-03-07 23:57:16
【问题描述】:

我为自己创建了一个投资组合网站。我使用 angular.js 来显示我的“关于我”文本内容以及我的投资组合图像和内容。即使在重新加载网站后,它也可以在我家的每台计算机上完美运行。截至上周,我收到报告说它在某些计算机上不起作用。我很难确定这是托管问题还是我的问题,因为报告它不工作的人一周前没有遇到这个问题,此后我没有更新它。

链接是http://www.davidsandersdesigns.com/。我觉得我在盲目地进行故障排除,因为即使在我的缓存被清空后,我的所有浏览器和机器上的一切都运行良好。我有时会收到 401 错误。有时我没有。请帮忙!

这是我的 json 文件。

{
"aboutMeContent": {
    "paragraph1":  "My name is David A. Sanders. I am a front-end web developer and graphic designer. I am fresh out of school and currently looking for a job where I may apply my skills, be challenged, and learn new things. I love design, creativity, web animation, ones/zeros, learning, french-pressed coffee, and my beautiful family…..did I mention my family? They are the reason I decided to pursue web development after all.",
    "paragraph2": "Aside from wrestling midgets (my kids), changing diapers, and day dreaming…..My top technical skills are HTML5, CSS3, JavaScript, Velocity.js, jQuery, and web animation. My top design skills are Photoshop, Illustrator, and just simple pencil and paper."
},
"portTileContent": [{
    "name": "Charlottes 3rd Birthday",
    "type": "Graphic Design/Print",
    "skills": "Adobe Illustrator",
    "notes": "This is a birthday card I created for my beautiful daughter. Picture courtesy of Photographer Carly Miller.",
    "link":"",
    "image": "images/viewerImages/CharBdayCard3yr_viewerImage.png"
}, {
    "name": "domSpace Animation Project",
    "type": "Web Design/Animation",
    "skills": "HTML5, CSS3, Velocity.js, Object-Oriented Javascript, Illustrator",
    "notes": "An Animation project I created to practice my programming skills.",
    "link": "<strong>Link:</strong> Visit the link <a href='http://www.davidsandersdesigns.com/domspace/' target=_blank>here<\/a>",
    "image": "images/viewerImages/domSpaceImage_viewerImage.png"
}, {
    "name": "Something Stiched Something Sewn",
    "type": "Graphic Design/Print",
    "skills": "Adobe Illustrator",
    "notes": "A business card I created for Donna Pierce/Seamstress.",
    "link": "<strong>Link:</strong> Visit her facebook <a href='https://www.facebook.com/SomethingStichedSomethingSewn/?fref=ts' target=_blank>here<\/a>",
    "image": "images/viewerImages/somethingStiched_viewerImage.png"
}, {
    "name": "davidsandersdesigns.com build 2000",
    "type": "Web Design/My Portfolio Site",
    "skills": "HTML5, SASS, Bootstrap3, Angular.js, Velocity.js, Illustrator, Photoshop",
    "notes": "My Personal site to showcase my work.",
    "link": "<strong>Link:</strong> You are already here!",
    "image": "images/viewerImages/dsdesignsBuild2000_viewerImage.png"
}]

}

这是我的控制器文件。

app.controller('myCtrl', function($scope, $http) {
$http.get("http://www.davidsandersdesigns.com/angular.js/data.json").success(function(data) {
    $scope.aboutMe = data.aboutMeContent;
    $scope.portTileSpecs = data.portTileContent;
});

});

这是我的应用文件

var app = angular.module('myApp', []);

angular.module('myApp')
.filter('to_trusted', ['$sce', function($sce){
    return function(text) {
        return $sce.trustAsHtml(text);
    };
}]);

【问题讨论】:

  • 401 是未经授权的消息。听起来更像是服务器配置问题或未显示授权代码。您对任何目录都有密码保护吗?
  • 尝试清除您的 cookie,您可能能够重现
  • 我只是检查以确保,所以我不知道。它在你的机器上运行吗?
  • 我有多次。我有朋友试用他们的机器。有些可以,有些不能。以前没有人在他们的机器上启动过该站点。这让我大吃一惊。但这似乎不是浏览器问题,因为它已在 chrome、IE、Firefox 和 safari 中运行
  • 为我在 Firefox 中工作。尝试隔离哪些浏览器出现错误

标签: javascript angularjs cross-browser


【解决方案1】:

我能够通过在 chrome 中打开没有 www 的站点来复制问题,但出现了 CORS 错误。

这是因为www.site.comsite.com在发出ajax请求时实际上被浏览器认为是跨域的。

改变:

$http.get("http://www.davidsandersdesigns.com/angular.js/data.json")

$http.get("/angular.js/data.json")

或者:

将服务器配置为在页面加载时始终重定向到 www 或不重定向到 www

人们已经习惯了在网址中不再需要www 的网站

【讨论】:

  • 好的,我刚刚解决了这个问题。它解决了问题吗?
  • 是的..在 chrome 中重新加载页面(没有 www)并且工作正常
  • 太棒了!它现在可以正常工作了!为什么有时能用有时不能用?
  • 可能是因为有些人使用www 而其他人没有
猜你喜欢
  • 2017-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多