首页 > 解决方案 > 如何将 AngularJS 响应传递给 window.url

问题描述

var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http){

$http({
                method: 'POST',
                url: '../api/CreateOrder',
                data: Object.toparams(myobject),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).then(function successCallback(response) {

                window.location.href = "checkout.html?OrderId=" + response.data;


            }, function errorCallback(response) {

                alert("Error. while updating user Try Again!");

            });

});

这是我的代码,我正在接收来自 http GET 的响应,如何将具有 OrderId 的响应数据作为参数传输到 window.location.href?

标签: angularjsquery-string

解决方案


response.data让我们假设[{OrderId : 25 }]然后尝试

window.location.href = "checkout.html?OrderId=" + response.data[0].OrderId;

推荐阅读