本文介绍了Ajax跨域请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ajax请求从我的本地域重定向到Paypal结帐域.我还允许跨域设置为true.但是我收到了

I am trying to redirect from my local domain to Paypal checkout domain using ajax request.I am also allowing cross domain to true.but I am getting the error that

  No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin      'http://localhost' is therefore not allowed access.

我的代码是:

$.ajax({
            type: 'GET',
            url: url,
            processData: false,
            crossDomain: true,
            contentType: "application/json",
            jsonp: false,
            success: function() {
                alert("Success");
            },
            error: function() {
                alert("failure");
            }
    });

推荐答案

为了允许CORS请求,服务器端需要在其中填充 Access-Control-Allow-Origin 标头响应.我认为贝宝(Paypal)服务器不执行此操作,因此这就是您收到错误的原因.

In order for a CORS request to be allowed, the SERVER side needs to populate the Access-Control-Allow-Origin Header in the response. I would presume that the Paypal servers do not do this and so this is why you are receiving the error.

有关更多信息,请参见以下链接: https://developer.mozilla.org/zh-CN/docs/HTTP/Access_control_CORS

For more information, see this link: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS

这篇关于Ajax跨域请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:48