6

这是购买东西的标准贝宝表格。

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="0.00">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

我不想要这种形式,我想用 angularJS 做到这一点:

<button ng-click="checkOut()" class="btn btn-default">Buy</button>

this.checkOut = function () {
            var data = {
               ... // handle all data
            };

            $http.post('https://www.paypal.com/cgi-bin/webscr', data).success(function (data) {
                console.log("success " + data);
            }).error(function (data) {
                console.log("error " + data);
            });
        }

这给了我一个错误:

XMLHttpRequest 无法加载https://www.paypal.com/cgi-bin/webscr。该请求被重定向到“ https://www.paypal.com/home ”,这对于需要预检的跨域请求是不允许的。

任何建议,如何在没有表格的情况下使用 angularJS?

4

1 回答 1

3

PayPal 目前不支持CORS,因此无法使用$http.

于 2014-05-23T14:11:39.110 回答