Angular提交POST表单

问题描述 投票:0回答:1

我需要将一些数据发送到外部页面,然后转到那些页面,是支付网关的页面。

如果没有Angular,我会在“action”和“method”帖子中创建一个目标页面的表单,提交此表单我会得到我需要的。

表格是这样的:

<form action="https://merchant.sparkling18.com/ppt-paygate/checkout" method="POST" name="submit1app8" id="submit1app8" >

    <input id="sqck.errorReturnUrl" name="sqck.errorReturnUrl" value="http://www.tantosvago.it/errore.asp" />

    <input id="sqck.userReturnUrl" name="sqck.userReturnUrl"  value="http://ws.tantosvago.it/1APP8/getstate1app8.php"/>

    <input id="scqk.customInfo" name="scqk.customInfo"  value="{&quot;answer&quot;:&quot;42&quot;,&quot;now&quot;:&quot;Wed Jul 02 21:08:31 UTC 2014&quot;}" />

    <input id="sqck.submitOrderData" name="sqck.submitOrderData"  value="eyJvcmRlciI6eyJtZXJjaGFudEl"/>

    <input type="submit" id="submitButton" />

</form>

现在,有角度我需要在没有形式的情况下做同样的事情。我必须发布一些数据(现在我将所有固定数据设置)到外部页面并去那里完成付款,这就是我所做的(在“app.js”中):

tantoSvagoApp.controller("checkoutController", function ($scope, $http, $location, $window, $httpParamSerializerJQLike ) {

        $scope.submit1app8 = function() {


            var parameters = {
                                "sqck.errorReturnUrl": "http://www.tantosvago.it/errore.asp",
                                "sqck.userReturnUrl": "http://tstest.tantosvago.it/1APP8/getstate1app8.php",
                                "scqk.customInfo": "{answer}", 
                                "sqck.submitOrderData": "eyJvcmRlci"
                            };


            $http({
                method  : 'POST',
                url     : 'https://merchant.sparkling18.com/ppt-paygate/checkout',
                data: $httpParamSerializerJQLike(parameters),
                headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  
            }).then(function success(response) {
                 console.log(response.data);
            }, function (response) {
                 console.log("Errore " + response.data,response.status);
            });

        };

});

这是我的HTML,一个调用我的函数的简单按钮:

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="js/angular.min.js"></script>
    <script src="js/assets/app.js"></script>
</head>
<body ng-app="tantoSvagoApp">

    <div ng-controller="checkoutController">
        <button type="submit" class="btn btn-default" ng-click="conferma_ordine()">Conferma Ordine</button>
    </div>
</body>

但什么都没发生,我不能去目的地页面(https://merchant.sparkling18.com/ppt-paygate/checkout

angular form-submit
1个回答
0
投票

如果您尝试在Angular中使用HTTP POST请求,则首先必须导入HttpClient模块。 Angular Docs提供了有用的信息。

https://angular.io/guide/http#making-a-post-request

© www.soinside.com 2019 - 2024. All rights reserved.