No #39;Access-Control-Allow-Origin#39; header is present on the requested resource- AngularJS(请求的资源上没有“Access-Control-Allow-Origin标头-AngularJS)
问题描述
XMLHttpRequest cannot load http://mywebservice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
当我尝试从我的代码中运行我的网络服务时,我收到了这个错误.我试图找到它并尝试了许多我在网上找到的建议的解决方案.粘贴下面的代码.
I get this error when I try to run my web-service from inside my code. I tried finding about it and tried many solutions which were suggested which I found on net. Pasting the code below.
<form name="LoginForm" ng-controller="LoginCtrl" ng-submit="init(username,password,country)">
<label>Country</label><input type="text" ng-model="country"/><br/><br/>
<label>UserName</label><input type="text" ng-model="username" /></br></br>
<label>Password</label><input type="password" ng-model="password">
</br>
<button type="submit" >Login</button>
</form>
和controller form对应的js是:
And controller form the corresponding js is:
app.controller('LoginController', ['$http', '$scope', function ($scope, $http) {
$scope.login = function (credentials) {
$http.get('http://mywebservice').success(function ( data ) {
alert(data);
});
}
}]);
当我从 URL 栏中点击它时,网络服务工作正常.如何解决问题?请帮忙!
The web-service works fine when I hit it from URL bar. How to resolve the problem? Kindly help!
推荐答案
Chrome Webstore 有一个扩展,当存在异步时会为您添加Access-Control-Allow-Origin"标头调用试图访问与您不同的主机的页面.
The Chrome Webstore has an extension that adds the 'Access-Control-Allow-Origin' header for you when there is an asynchronous call in the page that tries to access a different host than yours.
扩展名是:Allow-Control-Allow-Origin: *",这是链接:https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
The name of the extension is: "Allow-Control-Allow-Origin: *" and this is the link: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
这篇关于请求的资源上没有“Access-Control-Allow-Origin"标头-AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:请求的资源上没有“Access-Control-Allow-Origin"标头-AngularJS
基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01