提交表单时角度事件成功,它会打开弹出窗口

2024-04-21

我有一个页面通过角度 $http.post(..) 将数据发布到 ASPNET MVC 页面 当通话结束后,我必须提交一份表格。

基本上我做了以下事情:

<html ng-app>
<body data-ng-controller="testController">
    <form id="Checkpay" name="Checkpay" style="margin: 0" method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_blank" class="ng-pristine ng-valid">
        <input type="hidden" name="quantita" id="qtytext" value="0">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="item_name" value="Le Spose di Nika">
        <input type="hidden" name="business" value="[email protected] /cdn-cgi/l/email-protection">
        <input type="hidden" name="currency_code" value="EUR">
        <input type="hidden" name="cancel_return" id="cancel_return" value="">
        <input type="hidden" name="return" id="return" value="">
        <input type="hidden" name="no_shipping" value="1">

        <input type="hidden" id="H_amount" name="amount" value="719.80">
        <input type="hidden" id="H_first_name" name="first_name">
        <input type="hidden" id="H_address1" name="address1">
        <input type="hidden" id="H_city" name="city">
        <input type="hidden" id="H_state" name="state">
        <input type="hidden" id="H_zip" name="zip">
        <input type="hidden" id="H_email" name="email">
        <input type="hidden" id="Country" name="country">
        <input type="hidden" id="charset" name="charset" value="utf8">
        <input type="hidden" id="rm" name="rm" value="2">
        <input type="hidden" id="notify_url" name="notify_url" value="">

        <input id="Submit1" type="submit" value="submit_post" />
    </form>
    <input id="Submit2" type="button" data-ng-click='pay()' value="js_post" />

</body>



</html>

<script src="http://localhost:27433/Scripts/jquery-1.7.1.min.js"></script>
<script src="http://localhost:27433/Scripts/jquery-ui-1.8.20.min.js"></script>
<script src="http://localhost:27433/Scripts/angular.js"></script>
<script>

    function test() {

    }

    function testController($scope, $http) {
        var URL = "http://backend.MYSITE.com/";

        $scope.payTest = function () {


            var PAYPAL_URL_RELEASE = "https://www.paypal.com/cgi-bin/webscr";
            var PAYPAL_URL_SANDBOX = "https://www.sandbox.paypal.com/cgi-bin/webscr";

            $('#cancel_return').val(URL + '/ErrorPay');
            $('#return').val(URL + '/Success');
            $('#notify_url').val(URL + '/PayPalReceiverIPN.ashx?idOrder=');
            document.forms["Checkpay"].action = PAYPAL_URL_RELEASE;
            document.forms["Checkpay"].submit();

            console.log('paytest is executed!');
        }

        $scope.pay = function () {

            ////$.post(  URL + "/Order/Create", JSON.stringify({ newOrder: 1 }))
            ////    .success(function (datdata, status, headers, configa) {
            ////        console.log(' $.post success');
            ////        $scope.payTest();
            ////    }).error(function (data, status, headers, config) {
            ////        console.log(' $.post failure');
            ////    });


            $http.post(
               URL + "/Order/Create", JSON.stringify({ newOrder: 1 })
                 ).success(function (datdata, status, headers, configa) {
                     console.log('http success');
                     $scope.payTest();
                 }).error(function (data, status, headers, config) {
                     console.log('http failure');
                 });
        }
    }
</script>

当我执行 document.forms["Checkpay"].submit(); 时我希望有一个重定向 到我表单的属性操作中的页面,我得到了一个我要重定向的页面的弹出窗口。

我试图将函数 payTest() 置于“成功”之外并且它有效,然后我认为问题是 对象 $http (或 ajax)如何处理“成功”委托。

问题是:当 $http.post(....) finish 调用时,是否可以重定向页面?

thanks


您的 payTest 函数是否执行?

我会这样做:

function testController($scope, $http) {

     $scope.pay = function () {
        $http({
             method: 'POST',
             url: 'http://backend.mysite.com/Order/Create',
             data: JSON.stringify({ $scope.newOrder: 1 })
        })
        ['success'](function (data, status, headers, config) {
            console.log('http success');
            $scope.payTest();
        })
        ['error'](function (data, status, headers, config) {
             console.log('http failure');
        });
    };

    $scope.payTest = function() {

         console.log('paytest is executed!');
        // all your stuff

    }; 

}

更新:我将 $http 调用的语法更改为我经常使用的语法。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

提交表单时角度事件成功,它会打开弹出窗口 的相关文章

随机推荐