简体   繁体   English

为什么Wordpress无法将JavaScript文件加载到其他服务器上?

[英]Why won't wordpress load the javascript file on a different server?

I'm loading js in wordpress this way: 我以这种方式在wordpress中加载js:

function add_my_user_scripts() {
        wp_enqueue_script('myScriptsjs_user',plugins_url('/js/myScriptsjs_user.js', __FILE__),'','',true);
        wp_localize_script( 'myScriptsjs_user', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
    }

I need the myAjax for the files ajax call. 我需要myAjax来进行文件ajax调用。 This works on my test server but once I load it to the live server it js won't load. 这可以在我的测试服务器上运行,但是一旦我将其加载到实时服务器上,它将无法加载js。 Everything else loads fine on the live server including the css. 其他所有内容都可以在实时服务器(包括CSS)上正常加载。 I turned off the other plugins (still have the issue) and spit out the php errors and I don't get any conflicts. 我关闭了其他插件(仍然有问题)并吐出了php错误,但没有任何冲突。

I looked at my other plugins that use ajax and I did it the same way... loads fine. 我查看了其他使用ajax的插件,并以相同的方式进行了操作...加载正常。 Am I overlooking something obvious? 我是否忽略了明显的东西?

I think you're facing a problem of same origin policy . 我认为您正面临着原产地政策的问题。 It happens to me more than once using Ajax and you only realize this once you push your code on non-local servers. 使用Ajax对我来说不止一次,并且只有在将代码推送到非本地服务器上时,您才意识到这一点。 You can read more on the subject here . 您可以在此处阅读有关该主题的更多信息 Hope this will help solve your problem. 希望这会帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM