Paypal with angularjs $ http.post请求

时间:2022-08-22 19:39:04

This is the standard paypal form for buying stuff.

这是购买东西的标准paypal形式。

<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>

I don't want this form, I want to do this with angularJS:

我不想要这个表单,我想用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);
            });
        }

This gives me an error :

这给了我一个错误:

XMLHttpRequest cannot load https://www.paypal.com/cgi-bin/webscr. The request was redirected to 'https://www.paypal.com/home', which is disallowed for cross-origin requests that require preflight.

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

Any suggestions, how to do it angularJS, without the form?

任何建议,如何做到angularJS,没有形式?

1 个解决方案

#1


3  

PayPal doesn't support CORS right now so it's not possible to POST to PayPal using $http.

PayPal现在不支持CORS,因此无法使用$ http发送到PayPal。

#1


3  

PayPal doesn't support CORS right now so it's not possible to POST to PayPal using $http.

PayPal现在不支持CORS,因此无法使用$ http发送到PayPal。