OpenCart抛出JS错误';无法读取属性“”;文件“;为null的';当托管时


OpenCart throws JS error 'Cannot read property "document" of null' when hosted

当我在本地上尝试opencart时,它似乎工作得很好。但是当我上传到主机/服务器时,出现了一些错误,请参阅以下内容:

Uncaught TypeError: Cannot read property 'document' of null
f.each.contents @ jquery-1.7.1.min.js:3
e.extend.map @ jquery-1.7.1.min.js:2 
f.fn.(anonymous function) @ jquery-1.7.1.min.js:3 
(anonymous function) @ crossdomain.php?session_id=66e844dc45af19ce293981cdd9b22b67:566 
n @ jquery-1.7.1.min.js:2 o.fireWith @ jquery-1.7.1.min.js:2
e.extend.ready @ jquery-1.7.1.min.js:2
c.addEventListener.B @ jquery-1.7.1.min.js:2

问题出在哪里?因为在我的本地,这些错误不会出现。谢谢

运行托管和本地之间的一大区别是网络调用的安全处理。堆栈跟踪中对crossdomain.php的引用表明您遇到了这种情况。

如果是这样,那么有两种可能的解决方案:

如果你在Flash中运行:你需要在远程域的根目录下托管一个跨域.xml文件,该文件授予本地域(或者,在本例中,每个人)权限:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <allow-access-from domain="*" />
</cross-domain-policy>

该文件必须始终位于远程域的根。,http://something.com/crossdomain.xml。

如果不涉及Flash,那么CORS是负责阻止此调用的安全机制,您需要配置远程web服务器,以便在对您所访问的URL的响应中添加Access Control Allow Origin标头。

Access-Control-Allow-Origin: *