Angularjs http.get使用提供的用户名和密码获取http

时间:2015-11-11 12:58:41

标签: angularjs

我要连接的网站需要用户名和密码。我该如何实现呢?

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"/>

<div ng-app="myApp" ng-controller="customersCtrl"></div>

<script>
    var app= angular.module('myApp',[]);
    app.controller('customersCtrl',function($scope,$http){
        $http.get("http://xxx").success(function (response) {
            $scope.names = response.records;
        });
    });
</script>

1 个答案:

答案 0 :(得分:0)

您需要通过您的网址传递您的用户名和密码,例如:

<script>
    var app= angular.module('myApp',[]);
    app.controller('customersCtrl',function($scope,$http){
        $http.get("http://www.myWebPage/USERNAME:PASSWORD@blahblah.com").success(function (response) {
            $scope.names = response.records;
        });
    });
</script>