【发布时间】:2020-01-06 22:58:24
【问题描述】:
我正在angularJs 中创建一个页面,当我向我的 API 发送请求时,它会生成错误:
我的代码是:
<!DOCTYPE html>
<html ng-app="AppIndex">
<head>
<meta charset="utf-8">
<title>Hola mundo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js"></script>
<script src="ControllerIndex.js"></script>
</head>
<body ng-controller="ControllerIn">
{{"Hola Mundo" + nombre}}
<button ng-click="metodos()">Enviar</button>
<ul>
<li ng-repeat="response in posts">
<h2>holaaaaa</h2>
<p>{{response.title}}</p>
<p>{{response.body}}</p>
</li>
</ul>
</body>
</html>
和javascript
angular.module("AppIndex",[])
.controller("ControllerIn", function($scope, $http){
$scope.nombre = "Juan";
$scope.newPost = {};
$scope.responses = [];
$scope.metodos = function(){
$http({
method: 'POST',
url: 'http://localhost:900/Servicios/forgotPassword',
Headers: {"Access-Control-Allow-Origin": "http://127.0.0.1", "Access-Control-Allow-Methods": "POST", "Content-Type" : "application/json"},
data: {"user" : "admin1"}
}).then(function (response){
console.log(response);
$scope.posts = response;
},function (error){
console.log(error);
});
}
})
错误信息是:
发布http://localhost:900/Servicios/forgotPassword 403 {数据:“无效的 CORS 请求”,状态:403,配置:{...},状态文本:“”,标题:ƒ,...
我正在使用AngularJS 1.7.9
【问题讨论】:
-
CORS 在服务器上进行管理
标签: javascript html angularjs http-post