javascript - WooCommerce 中的 "SyntaxError: Unexpected token <"?

标签 javascript php html wordpress woocommerce

当我将我的 woocommerce-2.3.13 版本更改为 woocommerce-2.4.6 时出现此错误:

WooCommerce: SyntaxError: Unexpected token <

据我所知,当我在 php 文件上添加脚本标签 (< script>) 时,打开的脚本标签 <给出错误,这意味着它没有读取脚本标签。

我添加了我的插件(在 php 文件上)以将结帐流程与支付网关连接起来,以重定向到获取银行列表页面。当我尝试使用 JavaScript 重定向时出现此错误。重定向功能 header("location:$url")无法正常工作,所以我正在使用 JavaScript。

?>
<script type='text/javascript'>
   window.location.href="<?php  echo $url; ?>";
</script >
<?

我试过了

define('WP_DEBUG', false);error_reporting(0);@ini_set('display_errors', 0);

但我遇到了同样的错误。

最佳答案

当处理 WooCommerce 结账时,它要求网关返回一个数组(然后转换为 JSON)告诉结账是否成功。从 v1 开始就是这样。

在 2.4+ 中,这变得更加严格,因为响应必须是有效的 JSON。响应中的任何其他内容(例如 HTML、通知或空格)都会使此 JSON 无效,您可能会看到如下错误:

SyntaxError: Unexpected token

在这篇博客文章中查看调试它的方法 https://mikejolley.com/2015/11/12/debugging-unexpected-token-in-woocommerce-2-4/

我按照该博客文章中的所有说明进行操作,禁用了所有插件,结果发现 JSON 响应发回了一个错误,而不是格式正确的 JSON。我的回复是:

<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_SSLVERSION -     assumed 'CURLOPT_SSLVERSION' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Notice</b>:  Use of undefined constant CURLOPT_SSL_CIPHER_LIST - assumed 'CURLOPT_SSL_CIPHER_LIST' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
<br />
<b>Fatal error</b>:  Call to undefined function PayPal\Core\curl_version() in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConfig.php</b> on line <b>65</b><br />

就我而言,这是 WooCommerce PayPal Pro 支付网关和 WooCommerce 产品 vendor 的问题,因为默认情况下我的 DigitalOcean 服务器上未安装 cURL。对于 WooCommerce 产品 vendor ,每次客户下订单时, vendor 都会通过 PayPal Mass Payments 获得佣金。为使 PayPal 批量付款正常工作,您必须确保在您的 PayPal 帐户上启用批量付款并确保在您的服务器上安装了 cURL

我一安装 cURL,它就开始工作了。以下是如何在 DigitalOcean 上安装 cURL https://www.digitalocean.com/community/questions/curl-is-not-installed-in-your-php-installation

希望这对外面的人有帮助。

关于javascript - WooCommerce 中的 "SyntaxError: Unexpected token <"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690307/

相关文章:

javascript - 在日期选择器中启用一天作为工作日

php - 无法将数据从android发送到PHP

php - 根据 PHP 中包含的文件更改标题

html - CSS bootstrap text-right 不起作用

javascript - 是否可以使 "border-radius"trim 的边框不可点击?

jquery - 加载内容后加载广告

javascript - 如何判断具有多个单词的输入值是否包含 jQuery/javascript 中数组的值

javascript - localeCompare() 在移动浏览器上的奇怪行为

javascript - 为使用节点appendChild添加的列表创建事件监听器

php - mysql和重复条目报告