“贝宝” PHP 中没有定义
我在 ajax 中有代码,它调用 php 文件以在该页面中显示 paypal sdk 按钮:
function redirectPaypal() {
$('#tabs2').html('<img src="' + webroot + 'facebox/loading.gif">');
callAjax(webroot + 'TESTS.php', 'mode=paypall', function (t) {
// $.facebox(t);
$('#walletBg').removeClass('addBgColor');
$('#paypalBg').addClass('addBgColor');
$('#neverBg').removeClass('addBgColor');
$('#authBg').removeClass('addBgColor');
// $('#paymentInfo').show();
$('#tabs2').html(t);
});
}
如您所见,它使用模式值 paypal
调用 TESTS.php 文件。 TESTS.php 文件如下所示:
<?
require_once 'application-top.php';
require_once 'includes/navigation-functions.php';
require_once 'includes/site-functions-extended.php';
require_once 'includes/buy-deal-functions.php';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$post = getPostedData();
print_r($post);
if ($_POST['mode'] == 'paypall')
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Add meta tags for mobile and IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title> PayPal Checkout Integration | Client Demo </title>
</head>
<body>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD" data-namespace="paypal_sdk"></script>
<script>
// Render the PayPal button into #paypal-button-container
paypal_sdk.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '88.44'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// Replace the above to show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
</body>
</html>
<?
}
?>
文件已成功调用,但正如您看到下面的代码,调用页面时我收到引用错误:
VM1597:3
Uncaught ReferenceError: paypal_sdk is not defined
at eval (eval at <anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11369), <anonymous>:3:9)
at eval (<anonymous>)
at js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11369
at Function.globalEval (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11380)
at HTMLScriptElement.<anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:2538)
at Function.each (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11776)
at init.domManip (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:2441)
at init.append (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:3:32408)
at init.<anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:1283)
at Function.access (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:13266)
该错误与 TESTS.php 中调用的脚本有关:
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD" data-namespace="paypal_sdk"></script>
看来该文件未导入,或者 php 文件中有一些错误,我无法找到它。谁能帮我解决这个问题,因为我已经花了一整天的时间了。谢谢。
编辑: 我已将代码分开,如下所示,以防止首先预加载 papyal.button 代码。现在它如下所示:
<?
require_once 'application-top.php';
require_once 'includes/navigation-functions.php';
require_once 'includes/site-functions-extended.php';
require_once 'includes/buy-deal-functions.php';
?>
<script type="text/javascript" src="https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD"></script>
<?
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$post = getPostedData();
print_r($post);
if ($_POST['mode'] == 'paypall')
{
?>
<script src="https://example.com/TESTS.js"></script>
<?
}
?>
现在我收到如下错误:
GET https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD&_=1647908135353 net::ERR_ABORTED 400
当我检查错误代码时,请求的 src url 看起来有所不同,因为它在链接末尾添加了时间戳,因此我收到错误:
https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD&_=1647908731335
编辑2:
付款页面如下所示:
I have codes in ajax which calls php file to show the paypal sdk button in that page :
function redirectPaypal() {
$('#tabs2').html('<img src="' + webroot + 'facebox/loading.gif">');
callAjax(webroot + 'TESTS.php', 'mode=paypall', function (t) {
// $.facebox(t);
$('#walletBg').removeClass('addBgColor');
$('#paypalBg').addClass('addBgColor');
$('#neverBg').removeClass('addBgColor');
$('#authBg').removeClass('addBgColor');
// $('#paymentInfo').show();
$('#tabs2').html(t);
});
}
As you see it calls TESTS.php file with the mode value paypal
. The TESTS.php file is looks like below :
<?
require_once 'application-top.php';
require_once 'includes/navigation-functions.php';
require_once 'includes/site-functions-extended.php';
require_once 'includes/buy-deal-functions.php';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$post = getPostedData();
print_r($post);
if ($_POST['mode'] == 'paypall')
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Add meta tags for mobile and IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title> PayPal Checkout Integration | Client Demo </title>
</head>
<body>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD" data-namespace="paypal_sdk"></script>
<script>
// Render the PayPal button into #paypal-button-container
paypal_sdk.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '88.44'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// Replace the above to show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
</body>
</html>
<?
}
?>
File is called successfully but as you see the code below I am getting the reference error when the page is called :
VM1597:3
Uncaught ReferenceError: paypal_sdk is not defined
at eval (eval at <anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11369), <anonymous>:3:9)
at eval (<anonymous>)
at js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11369
at Function.globalEval (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11380)
at HTMLScriptElement.<anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:2538)
at Function.each (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:11776)
at init.domManip (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:2441)
at init.append (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:3:32408)
at init.<anonymous> (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:4:1283)
at Function.access (js.php?f=js%2Fjquery-1.7.2.min.js%2Cjs%2Fmodernizr.custom.02358.js%2Cfunctions.js.php%2Cjs%2Fsite-functions.js%2Cform-validation.js.php%2Cform-validation-lang.php%2Cjs%2Fjquery-ui.min.js%2Cfacebox%2Ffacebox.js%2Cjs%2Fmbsmessage.js&min=1&sid=1631542832:2:13266)
The error is related to the script which is called in TESTS.php :
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD" data-namespace="paypal_sdk"></script>
It seems the file is not imported or there is some errors in php file which I am not able to find it out. Can anyone help me with this please as I have spent my whole day on it. Thanks.
EDIT :
I have seperated the codes like below in order to prevent the preloading the papyal.button codes first. And now it looks like below :
<?
require_once 'application-top.php';
require_once 'includes/navigation-functions.php';
require_once 'includes/site-functions-extended.php';
require_once 'includes/buy-deal-functions.php';
?>
<script type="text/javascript" src="https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD"></script>
<?
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$post = getPostedData();
print_r($post);
if ($_POST['mode'] == 'paypall')
{
?>
<script src="https://example.com/TESTS.js"></script>
<?
}
?>
Now I am getting the error like below :
GET https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD&_=1647908135353 net::ERR_ABORTED 400
When I checked the error code the requested src url is looking like different as it adds the timestamp at the end of the link therefore I am getting the error :
https://www.paypal.com/sdk/js?client-id=AQgUM6x3URK1A-rcNIq56covuc0CYGv3pb5sYeL6-cqsO1HYV2CV6h4ur6BCly_1YYd3-UOMTNGtwQXd¤cy=USD&_=1647908731335
EDIT 2:
The payment page looks like below :
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必注入整个页面。你可以做这样的事情。
You don't have to inject the whole page. You can do something like this.
任何遇到这种情况的人只需使用如下代码:
以这种方式加载脚本是异步的,并且需要时间,因此事件
onload
必须用作回调。Anyone who is struggling with this case just use the code like below :
Loading a script that way is asynchronous and takes time therefore the event
onload
must be used as callback.