“SyntaxError:意外的令牌<”在WooCommerce?

时间:2015-09-21 08:11:34

标签: javascript php html wordpress woocommerce

当我将woocommerce-2.3.13版本更改为woocommerce-2.4.6时,我收到此错误:

  

WooCommerce:SyntaxError:意外的令牌<

据我所知,当我在php文件中添加脚本标记(< script>)时,打开的脚本标记DATETIME会出错,这意味着它不会读取脚本标记。

我添加了我的插件(在php文件中),将结帐流程与支付网关连接,以重定向到银行列表页面。当我尝试使用JavaScript重定向时,会出现此错误。重定向功能<无效,因此我使用的是JavaScript。

header("location:$url")

我试过

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

但是我遇到了同样的错误。

1 个答案:

答案 0 :(得分: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产品供应商存在问题,因为默认情况下我的DigitalOcean服务器上没有安装cURL。使用WooCommerce产品供应商,每次客户下订单时,供应商都会通过PayPal Mass Payments获得付款佣金。要使PayPal批量付款生效,您必须确保在PayPal帐户上启用批量付款,并确保服务器上已安装cURL

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

上安装cURL

希望这可以帮助那些人。