如何使用angularjs在post API之后放置令牌?

时间:2018-01-12 03:49:20

标签: angularjs

我想问一下......如何在执行POST API数据后检索令牌

这是数据

$scope.SubmitText = function(form){
                    console.log($scope.email)
                    var params = {
                        asalKota: 76,
                        emailPemesan: $scope.email,
                        hargaBayar: 370000,
                        idAgenBerangkat: 31,
                        idPemesan: 1,
                        idArahTrayek: 23,
                        idSubTrayek: 15,
                        idJadwal: 2976,
                        jmlPenumpang: 2,
                        kotaAsal: 'Yogyakarta',
                        kotaTujuan: 'Jakarta',
                        metodePayment: 'transfer',
                        namaPemesan: 'Muhammad Soleh',
                        penumpangs: [
                            {
                                gender: 'pria',
                                id: '1',
                                kursi: '30',
                                nama: 'Muhammad Soleh',
                                kategoriUsia: 'dewasa'
                            }
                        ],
                        telponPemesan: '089634756000',
                        tgl: '2018-01-30',
                        tujuanKota: 1,
                        waktu: '15:30',
                        zonaWaktu: 'WIB'
                    };
                    $http.post('http://dev.otodata.co.id:8181/order/tiket/' , params)
                    .then(function(data){
                        $scope.SubmitText = data;
                        console.log($scope.SubmitText);
                        window.location.href = "https://app.sandbox.veritrans.co.id/snap/v2/vtweb/" + $scope.SubmitText.redirect_url;
                    });
                };

但是当我执行时,没有拾取令牌。如何获取令牌? imageTokenHere

请帮助,谢谢

1 个答案:

答案 0 :(得分:0)

请您尝试以下代码。

    $http({
            method  : 'POST',
            url     : "YOUR_URL",
            headers : { 'Authorization': 'Token ' + accessToken }
        })
        .success(function(data, status){
            deferred.resolve(data);
        }).error(function (error){
            console.log(error);
            deferred.reject();
        });