2015-05-09 56 views
2

我从我的magento项目获取js错误如下。我的项目URL是check my project。我认为这是与原型js.i错误,我试过js noconflict但没用。原型的Java脚本错误

错误:

Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value)(intermediate value)(intermediate value) is not a function www.bigzaar.com/:1 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:93 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:151 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:157 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:420 Uncaught ReferenceError: jQuery is not defined jquery.mobile.customized.min.js:10 Uncaught ReferenceError: jQuery is not defined camera.js:2238 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:607 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:704 Uncaught ReferenceError: jQuery is not defined www.bigzaar.com/:863 Uncaught ReferenceError: jQuery is not defined

我的js文件

/********Javascript for FREE TEXT SEARCH ************/ 
var Quicksearch = Class.create(); 
var idSearchInput = ''; 
Quicksearch.prototype = { 
    initialize: function(searchUrl,resultNotice,idSearchInput){ 
     this.idSearchInput = idSearchInput; 
     this.searchUrl = searchUrl;  
     this.onSuccess = this.onSuccess.bindAsEventListener(this);   
     this.onFailure = this.onFailure.bindAsEventListener(this);    
     this.currentSearch = '';  
     this.resultNotice = resultNotice; 
    }, 
    search: function(){ 
     var searchBox = $(this.idSearchInput); 

     if(searchBox.value=='') 
     { 
      return; 
     } 

     if ((this.currentSearch!="") &&(searchBox.value == this.currentSearch)) { 
      return; 
     } 
     this.currentSearch = searchBox.value; 

     searchBox.className = 'loading-result input-text'; 
     var keyword = searchBox.value; 


     url = this.searchUrl+"keyword/" + escape(keyword); 

     new Ajax.Request(url, { 
       method: 'get',   
       onSuccess: this.onSuccess, 

       onFailure: this.onFailure 
      });  
    }, 
    onFailure: function(transport){ 
     $(this.idSearchInput).className ="input-text"; 
    }, 
    onSuccess: function(transport) 
    { 
     var showResults = $('showResults'); 
     showResults.style.display = "block"; 
     var listResults = $('listResults'); 
     listResults.style.display = "block"; 
     var searchBox = $(this.idSearchInput); 
     if (transport && transport.responseText) { 
      try{ 
       response = eval('(' + transport.responseText + ')'); 
      } 
      catch (e) { 
       response = {}; 
      } 

      if (response.html != "") { 
       this.currentSearch = searchBox.value; 
       listResults.update(response.html); 
       var searchResultNotice = this.resultNotice; 
       var strNotice = searchResultNotice.replace("{{keyword}}",this.currentSearch); 
       this.updateResultLabel(strNotice); 
       searchBox.className = 'search-complete input-text'; 
      } 
      else 
      { 
       listResults.update(response.html); 
       this.updateResultLabel('No results for "<span class="keyword">'+this.currentSearch+'</span>"'); 
       searchBox.className ="search-complete input-text"; 
      }   
     }  
    }, 
    updateResultLabel: function(message) 
    { 
     $("resultLabel").update(message); 
    } 
} 

我的js调用函数

<script type="text/javascript"> 
    var quicksearch = new Quicksearch(
     '<?php echo $this->getUrl('freetextsearch/search/quicksearch') ?>', 
     '<?php echo $resultNotice ?>', 
     'input_search' 
    ); 
    var numberChar = <?php echo Mage::getStoreConfig('freetextsearch/quick_search_setting/number_character')?>; 
    Event.observe('input_search', 'keyup', function(event){ 
     var searchBox = $('input_search'); 
     if(searchBox.value.length >= numberChar){ 
      quicksearch.search(); 
     } 
    }); 
    function closeDropdown() { 
     var showResults = $('showResults'); 
     showResults.style.display = "none"; 
    } 
</script> 

请帮我解决这个error.any帮助将很可观

+0

其他帮助? –

回答

1

使用Chrome De bugger控制台并在“来源”面板中启用“暂停异常”。 Chrome会直接向您显示发生异常的行。如果没有,重新加载页面一次或两次(如果脚本内嵌在模板中某处,并且在Opera或其他基于Webkit的浏览器中使用该调试器,那么这是必要的;而在Chrome中,即使对于内联脚本,它也可以在大部分时间内运行)。

我看到您在包含jQuery 1.8之前尝试使用jQuery。确保在包含jQuery库之前不要使用jQuery。

在缩小的jQuery 1.8 lib中引发了异常。目前还不清楚究竟是什么导致jQuery 1.8 lib抛出一个异常,我建议你包含未压缩的版本,以便你可以看到发生异常的位置。我也看到压缩版本的jQuery抛出异常,而未压缩的版本不在Magento中。使用未压缩的版本可以神奇地“解决”你的问题,但压缩版本不能正常工作主要是提示jQuery或原型脚本之间的某种冲突。

请确保你不使用扩展也包括jQuery脚本。在一个页面中的多个jQuery版本可能会导致冲突,这可以通过noconflict来解决。

从我的经验来看,如果您在head.phtml中为所有用途包含jquery,并添加jQuery.noconflict()之后那。然后通过布局xml一次包含所有magento原型脚本,然后添加其他任何jQuery脚本,并确保始终封装每个jQuery脚本,如下所示。

确保使用$作为快捷方式每jQuery脚本被封装这样的:

jQuery(function($) { 

    //your code using jQuery in $ notation 

    $(document).ready(function() { 
     //code that needs to wait for complete load of DOM 
    }); 
}); 

我的计算器上的第一个答案,希望我能帮助。

+0

感谢您的建议@HGeist –