2012-08-01 102 views
1

我有一个Wordpress网站,最终是一个流式广播网站。在标头,我是从我的专用服务器的CP拉流数据(如听众数和当前播放)的脚本。(Centova演员)

我注册function.php脚本:

这是寄存器

wp_register_script(’streaminfo’, 'http://94.23.250.14:2199/system/streaminfo.js',false,null); wp_enqueue_script(’streaminfo’);

这是在整个jQuery的部分供您查看..

/* ------------------------------------ 

:: INITIATE JQUERY/STYLING 

------------------------------------ */ 

function init_dynscripts() { 
    if (!is_admin()) { 

     if (function_exists('bp_is_blog_page')) { 
      if (!bp_is_blog_page()) { 
       wp_enqueue_script('bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array('jquery')); 
      } 
     } 

     wp_register_style('northvantage-style', get_bloginfo('stylesheet_url'),false,null); 
     wp_enqueue_style('northvantage-style'); 


     if(get_option('enable_responsive')!='disable') : 

     wp_register_style('northvantage-responsive', get_template_directory_uri().'/stylesheets/responsive.css',false,null); 
     wp_enqueue_style('northvantage-responsive'); 

     endif; 

     wp_enqueue_script('jquery-ui-core',false,null); 
     wp_enqueue_script('jquery-ui-tabs',false,null); 
     wp_enqueue_script("jquery-ui-accordion",false,null); 
     wp_enqueue_script("swfobject",false,null); 
     wp_deregister_script("jquery-effects-core"); 

     wp_deregister_script('libertas'); 
     wp_register_script('libertas',get_template_directory_uri().'/js/nv-script.pack.js',false,null); 
     wp_enqueue_script('libertas'); 
     wp_register_script(’streaminfo’, 'http://94.23.250.14:2199/system/streaminfo.js',false,null); 
     wp_enqueue_script(’streaminfo’); 
     wp_register_script(’jpie’, get_template_directory_uri().'/js/jpie.js',false,null); 
     wp_enqueue_script(’jpie’); 
     wp_register_style('jpiestyle', get_template_directory_uri().'/jpie.css',false,null); 
     wp_enqueue_style('jpiestyle'); 


     if(get_option('jwplayer_js')) { // Check jw player javascript file is present 

     $NV_jwplayer_js = get_option('jwplayer_js'); 

     wp_deregister_script('jw-player');  
     wp_register_script('jw-player', $NV_jwplayer_js,false,null); 
     wp_enqueue_script('jw-player');  
     } 
    } 
}  
add_action('init', 'init_dynscripts',100); 


function _remove_script_version($src){ // remove script version 
    $parts = explode('?', $src); 
    return $parts[0]; 
} 
add_filter('script_loader_src', '_remove_script_version', 15, 1); 
add_filter('style_loader_src', '_remove_script_version', 15, 1); 

看来我有streaminfo之间的冲突。 JS和我的网站。 元素检验得出:

Uncaught TypeError: Property '$' of object [object Window] is not a function

为了让事情short..everything我试图与文件结束了错。

我试着改变每个$符号到文件中的jQuery,它消除了冲突,但与其他文件产生冲突。

我尝试添加

jQuery(document).ready(function ($) {

到文件的头部,但它打破对CP的其他元素。

最终我跑了一个简单的测试,并创建了一个网页,只有这样的代码:

<html> 
<body> 
<span id="cc_strinfo_title_tranceilfm" class="cc_streaminfo"></span> 
<script language="javascript" type="text/javascript" src="http://94.23.250.14:2199/system/streaminfo.js"></script> 
</body> 
</html> 

和页面没有返回任何错误。 (我包括谷歌jQuery文件的路径)

在WordPress的东西搞乱了jQuery插件?或者我的代码中缺少一些字符串?

www.tranceil.fm

回答

4

尝试在您的document.ready顶部添加jQuery.noConflict()。这将解除绑定$变量,这应该消除你的冲突。

在回应我们的意见的讨论,并帮助其他人谁看到这个问题,这里的概述一点:

如何jQuery和jQuery.noConflicts()工作:

当你加载jQuery库,创建一个名为jQuery的变量,它代表“jQuery”函数。还创建了名称为$jQuery的别名。

无论出于何种原因,其他几个JavaScript库都会更改$别名以表示它们自己的函数。发生这种情况时,您会发生冲突,因为两种不同的事情都试图控制$变量。 jQuery.noConflict()所做的是将$jQuery关联,允许任何其他尝试使用$的地方自由使用它。

美中不足的是,现在$并不是指jQuery,所以处处要访问jQuery对象,你需要使用jQuery,而不是$

+0

像这样? jQuery.noConflict(document).ready(function($){我应该如何关闭它?http://94.23.250.14:2199/system/streaminfo.js – Trance84 2012-08-01 17:15:18

+0

像这样:jQuery(document).ready(function() {jQuery.noConflict();}); – 2012-08-01 17:17:21

+0

Uncaught TypeError:无法调用null的方法'match':( – Trance84 2012-08-01 17:19:35