2015-01-06 18 views
0

我正在Laravel 4中使用omnipay實現Paypal Express。 狀態碼:302當我的網站嘗試重定向到PayPal時發現。不能重定向到PayPal使用omnipay與標題中的JQuery

錯誤:

XMLHttpRequest cannot load https://www.sandbox.paypal.com/xxxxxxxx . No 'Access-Control-Allow-> Origin' header is present on the requested resource. Origin ' http://www.example.com ' is ??> therefore not allowed access.

其實我發現,如果我刪除以下Jquery的頭在我purchase.blade.php它會正常工作。我正在使用Controller將調用提交給paypal(不是ajax調用)。

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> 
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 

不過,我需要Jquery。 任何想法或解決方法?

謝謝

+0

這可能是一個類似的問題在這裏描述和很好的回答:http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource –

+0

你可以發佈你正在執行的代碼嗎?你有沒有嘗試將你的jQuery腳本設置爲https?您自己的服務器是否以HTTPS或HTTP運行? – danielwinter

回答

0

可能有點晚,但我最近有類似的問題。我正在使用AngularJS作爲我的前端,並且使用一項服務來調用我的CodeIgniter API以供Omnipay使用。

Omnipay重定向到Sandbox,但是您希望將URL返回到您的JS或Jquery,而不是立即從CodeIgniter/Laravel /任何服務器端框架重定向。解決方案

:不是:

$response->redirect(), 

將其替換爲:

$url = $response->getRedirectUrl(); 
    print_r($url); 

因此,URL返回爲一個回調到您的Javascript,並在你的JavaScript(我用角JS )控制器,你可以在window.location中加載它。

angular.module('gateway',[]) 
.controller('payCtrl', function ($scope,payService,$window){ 
$scope.paymentParams={}; //payment params from your form 
payService.makePayment($scope.paymentParams) //send payment details to server 
    .success (function (data){ 
    $window.location=data; // the data will be "https://www.paypal.com etc etc, which you will pass to the $window service to redirect to the location. 

    }) 
    .error (function (err){ 
    //handle error 
    }); 
}); 

希望它能幫助那裏的人。