Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在js中获取请求_Javascript_Angularjs - Fatal编程技术网

Javascript 在js中获取请求

Javascript 在js中获取请求,javascript,angularjs,Javascript,Angularjs,在Angular js XMLHttpRequest cannot load http://localhost:29527/Services/ProfileService.svc/ChildList?ParentId=37. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed a

Angular js

 XMLHttpRequest cannot load http://localhost:29527/Services/ProfileService.svc/ChildList?ParentId=37. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. 
这是我的密码

app.controller("AppCtrl", function($http) {
    var app = this;
    var config = {
        headers: {
            'Authorization': 'Basic d2VudHdvcnRobWFuOkNoYW5nZV9tZQ==',
            'Accept': 'application/json;'

        }
    };

    $http.get(childList,config)
        .success(function(data) {
            var carsFromServer = JSON.parse(data);
            console.log(data.getChildrenResult);
        });
});

这是因为
http://localhost:29527/Services/ProfileService.svc/ChildList?ParentId=37
没有
访问控制允许原点
标题。这会导致
XMLHttpRequest
失败,因为origin
http://localhost:63342
(html所在的位置)不允许从其他来源读取数据

你真的看过错误消息了吗?

短篇小说
起初,网站可以从其他网站加载数据。但很快人们就明白了这是非常危险的,因为黑客可以从其他网站窃取cookie。所以引入了CORS(跨源资源共享)标准,它不允许网站加载来自不同域的数据。但它仍然可以配置

你的问题
您的url
http://localhost:29527/Services/ProfileService.svc/ChildList?ParentId=37
似乎是一个wcf服务,它可能是自托管的,但在实现上述功能并在webserver中托管wcf之前,您不能将其用于跨域原始请求。在wcf中启用CORS有时会带来很多麻烦,因为wcf在默认情况下非常有限,在某些情况下甚至不可能。只是因为wcf不理解http请求,并且剪切了很多头信息。以前提供的链接应该暂时解决,但是

建议
使用wcf服务的服务引用创建WebApi站点,添加您需要的所有内容(路由、控制器、操作),并通过向控制器应用属性(非常简单)实现CORS。因此,您将最终完成3个项目(wcf服务、asp.net webapi、angularjs网站)。或者最好使用angularjs作为wcf的Web服务。但拥有独立的webapi服务器将是非常灵活的,因为您可能想要制作移动版本,或者仅仅是移动本机应用程序,或者任何您想要的东西。它将为一切服务

希望有帮助。很抱歉用英语

尝试使用$http.jsonp而不是$http.get check out

我尝试了这个
标题:{'Access-Control-Allow-Origin':'*}
但它没有做任何更改raghu,您是否尝试在为您的API提供服务的本地主机服务器上设置了'Access-Control-Allow-Origin':'*'呢?这就是你需要处理的问题的一面。接受服务器需要允许跨源资源共享。这并不奇怪。再次阅读此消息-它是关于资源的,而不是请求。请仔细阅读同源策略。如果采用错误的方法,可能会引入一个重大的安全漏洞。