集成Paypal时跨域请求阻止错误

时间:2018-10-31 06:59:36

标签: ajax asp.net-mvc model-view-controller asp.net-ajax

在集成Paypal时出现以下错误:

跨域请求被阻止:“同源起源”策略不允许读取https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2HF34205DN464620R处的远程资源。 (原因:CORS标头“ Access-Control-Allow-Origin”缺失)。 跨域请求被阻止:同源策略禁止读取https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-2HF34205DN464620R处的远程资源。 (原因:CORS请求未成功)。

获取请求:

function notEmpty() {
            $.ajax({
                url: 'https://companionstest.azurewebsites.net/Payment/PaymentWithPayPal',
                headers: {
                    'Content-Type': 'text/html',
                   // 'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Origins': '*',
                   'Access-Control-Allow-Credentials': 'true',
                    'Access-Control-Max-Age': '3600',
                    'Access-Control-Allow-Methods': 'GET',
                    'async': 'true',
                    'crossDomain': 'true',
                    'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
                    'Accept': 'text/html'
                },

                type: "GET", /* or type:"GET" or type:"PUT" */
                async:"false",
               // dataType: "text/html", 
                success: function (data) {
                    window.location.href = data.redirecturl;
                },
                error: function (httpRequest, textStatus, errorThrown) {  // detailed error messsage 
                    alert("Error: " + textStatus + " " + errorThrown + " " + httpRequest);
                }
            });

}

0 个答案:

没有答案