在IE9本地磁盘问题Angularjs $ HTTP负载数据 [英] Angularjs $http load data from local disk issue in IE9

查看:373
本文介绍了在IE9本地磁盘问题Angularjs $ HTTP负载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angularjs,角-1.2.0-rc.2

Angularjs, angular-1.2.0-rc.2

$http.get("gridData.json")
        .success(function(data, status, headers, config){
            angular.extend($scope.model.entities, data.entities);
        })
        .error(function(data, status, headers, config){
            alert("x");
        });

这code运行完全正常时,负载从服务器,或者当网页上运行使用Firefox或Chrome本地磁盘上的页面。但是,当负载从磁盘上的页面在IE9(其他版本的IE浏览器没有测试),它总是错误的功能。调试时,当错误发生时,数据,身份,头都是不确定的,除了配置有内容。

This code runs perfectly fine when load the page from server, or when run the page on local disk using firefox or chrome. But when load the page from disk in IE9 (didn't test in other IE version), it always go to error function. When debugging, when error happen, the data, status, headers all are undefined, except config has content.

任何人有什么想法?可能是任何解决方案?

Anyone have any idea? Could be any solution?

推荐答案

这是由于的同源策略你会看到同样的错误铬。 Chrome和IE不允许本地Ajax请求。有很多方法可以做到这一点,例如铬,你将不得不使用一些特殊的标志启动

it is due to same origin policy You would see same error in chrome. Chrome and IE does not allow local ajax requests. there are ways to do that for example chrome you would have to start it with some special flags

http://joshuamcginnis.com/2011/02/28/how-to-disable-same-origin-policy-in-chrome/

C:\Users\YOUR_USER\AppData\Local\Google\Chrome\Application\chrome.exe --allow-file-access-from-files --disable-web-security

和在IE中可以减少您的安全设置是微乎其微。

and in ie you can reduce your security settings to be minimal.

有其他的解决方案
喜欢
<一href=\"http://stackoverflow.com/questions/14670639/jquery-ajax-run-as-a-local-html-file-avoiding-sop-same-origin-policy\">jQuery $就运行作为本地的HTML文件,避免SOP(同源策略)

使用jQuery的

$.support.cors = true;

另外一个解决方案结果
尝试把JSON数据js文件或服务器这样你就不必做任何Ajax请求到本地文件

Another Solution
try to put the json data in js file or your server that way you don't have to do any ajax request to local file

其他来源:结果
方式来规避同源策略结果
<一href=\"http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/\" rel=\"nofollow\">http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

这篇关于在IE9本地磁盘问题Angularjs $ HTTP负载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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