【问题标题】:Paypal with angularjs $http.post requestPaypal 与 angularjs $http.post 请求
【发布时间】:2014-02-21 09:11:51
【问题描述】:

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

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

【问题讨论】:

  • 如果您想使用 Paypal 的服务,您需要使用他们的 API,而不仅仅是复制他们的代码并期望它以同样的方式工作。你想做什么?

标签: javascript angularjs paypal angular-http


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-02-23
    • 1970-01-01
    • 2015-04-16
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多