Angularjs如何传递多个参数和标头值

时间:2017-01-17 12:31:55

标签: angularjs angular-http

错误 对预检请求的响应没有通过访问控制检查:否'访问控制 - 允许 - 来源'

上有标题
var myApp = angular.module("myApp", []);
myApp.controller('TestingCtrl', function ($scope, $http) {
    var GetData = function () {

        $http({
            method: "GET",
            url: 'http://103.22.11.11/Buses/Sources'

        }).success(function (response) {
            $scope.Return = response.Id[0];
            alert("ddd");

        })
    }
    GetData();
})

我该如何传递此标题

                'ConsumerKey': '811D72785AC287ACE3E8',
                'ConsumerSecret': 'C80A758DCC6BCEBE436D25BC'

1 个答案:

答案 0 :(得分:0)

你有没有试过以下。

  var myApp = angular.module("myApp", []);
    myApp.controller('TestingCtrl', function ($scope, $http) {
    var GetData = function () {

        $http({
            method: "GET",
            url: 'http://103.22.11.11/Buses/Sources',
            data:{'dummy':'dummy'},
            headers: {'Content-Type':'application/json',
             'ConsumerKey': '811D72785AC287ACE3E8',
                'ConsumerSecret': 'C80A758DCC6BCEBE436D25BC'}

        }).success(function (response) {
            $scope.Return = response.Id[0];
            alert("ddd");

        })
    }
    GetData();
   });