这是我第一次尝试angular js,而且我关注了很多文章,但没有获得成功。
我正在尝试使用php api使用angular js登录,但我总是收到此响应
{“数据”:null,“状态”:-1,“配置”:{“方法”:“ POST”,“ transformRequest”:[null],“ transformResponse”:[null],“ url”: “ http://xyz/api/login”, “ data”:{“ email”:“ xyz@g.com”,“ password”:“ 456987”},“ headers”:{“ Accept”:“ application / json, 文字/纯文字, / “,”内容类型“:” application / json; charset = utf-8“}},” statusText“:”“}
<!DOCTYPE html>
<html>
<head>
<title>
AngularJs $http.post() Service Response Example
</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('postserviceApp', []);
app.controller('postserviceCtrl', function ($scope, $http) {
$scope.postdata = function (email, password) {
var data = {
email: $scope.email,
password: $scope.password
};
//Call the services
$http.post('url', data).then(function (response) {
if (response.code)
$scope.msg = "Post Data Submitted Successfully!";
}, function (response) {
$scope.response=response
$scope.msg = "Service not Exists";
$scope.statusval = response.status;
$scope.statustext = response.statusText;
$scope.headers = response.headers();
});
};
});
</script>
</head>
<body>
<div ng-app="postserviceApp" ng-controller="postserviceCtrl">
<div>
Email : <input ng-model="email" /><br/><br/>
Password : <input type="password" ng-model="password" /><br/><br/>
<input type="button" value="Send" ng-click="postdata(email, password)" /> <br/><br/>
</div>
<p>Output Message : {{response}}</p>
<p>StatusCode: {{statusval}}</p>
<p>Status: {{statustext}}</p>
<p>Response Headers: {{headers}}</p>
</div>
</body>
</html>
我在开发人员控制台中收到此错误消息
无法加载网址:对预检请求的响应未通过访问 控件检查:上不存在“ Access-Control-Allow-Origin”标头 请求的资源。因此,不允许访问原始“空”。
那是什么意思?