无法加载Angular js中的资源错误

Failed to load resource error in Angular js

本文关键字:资源 错误 js 加载 Angular      更新时间:2024-03-19

当尝试在角度中运行以下函数时

$scope.login = function (user, LoginForm) {
        $http.get('http://localhost/Angular/index.php/core/login').success(function (data) {
            $scope.message = data;
        });
    };

它显示以下错误

(我在网络风暴中使用此代码)

加载资源失败:服务器响应状态为404(未找到)

http://localhost/Angular/index.php/api/login:0

未能加载资源:请求的资源上不存在"Access Control Allow Origin"标头。因此,不允许访问源"http://localhost:63342'"。

http://localhost/Angular/index.php/api/login:0

XMLHttpRequest无法加载http://localhost/LAngular/index.php/api/login。请求的资源上不存在"Access Control Allow Origin"标头。因此,不允许源'http://localhost:63342'访问。

如何解决此问题?

这表示Api不支持跨来源请求

因此请求应该是"JSONP"

$http.jsonp('http://localhost/Angular/index.php/core/login')

有关此问题的详细信息:http://www.arunisrael.com/2013/08/accessing-external-apis-with-angularjs.html