2011-04-19 56 views
2

警告:文本jQuery.csv()插件未知错误

我使用jQuery.csv插件到csv加载到阵列的壁。它工作得很好,直到最近。我不知道如果有什么改变,但不是工作,它会显示在控制台中出现以下错误:

Uncaught TypeError: Object function (a,b){return new c.fn.init(a,b)} has no method 'csv' 

我呼吁它(方法同我之前)使用插件文档中描述的方法:

jQuery.get(csvfile, function(data) { array = jQuery.csv()(data); }); 

插件文件本身是很短:

/* Usage: 
    * jQuery.csv()(csvtext)    returns an array of arrays representing the CSV  text. 
    * jQuery.csv("\t")(tsvtext)   uses Tab as a delimiter (comma is the default) 
    * jQuery.csv("\t", "'")(tsvtext)  uses a single quote as the quote character instead of double quotes 
* jQuery.csv("\t", "'\"")(tsvtext) uses single & double quotes as the quote character 
*/ 
; 
jQuery.extend({ 
    csv: function(delim, quote, linedelim) { 
     delim = typeof delim == "string" ? new RegExp("[" + (delim || "," ) + "]") : typeof delim == "undefined" ? "," : delim; 
     quote = typeof quote == "string" ? new RegExp("^[" + (quote || '"' ) + "]") : typeof quote == "undefined" ? '"' : quote; 
     lined = typeof lined == "string" ? new RegExp("[" + (lined || "\r\n") + "]+") : typeof lined == "undefined" ? "\r\n" : lined; 

     function splitline (v) { 
      // Split the line using the delimitor 
      var arr = v.split(delim), 
       out = [], q; 
      for (var i=0, l=arr.length; i<l; i++) { 
       if (q = arr[i].match(quote)) { 
        for (j=i; j<l; j++) { 
         if (arr[j].charAt(arr[j].length-1) == q[0]) { break; } 
        } 
        var s = arr.slice(i,j+1).join(delim); 
        out.push(s.substr(1,s.length-2)); 
        i = j; 
       } 
       else { out.push(arr[i]); } 
      } 

      return out; 
     } 

     return function(text) { 
      var lines = text.split(lined); 
      for (var i=0, l=lines.length; i<l; i++) { 
       lines[i] = splitline(lines[i]); 
      } 
      return lines; 
     }; 
    } 
}); 

我使用jQuery.noConflict()正是如此:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript"> 
    jQuery.noConflict(); 
</script> 
<script type="text/javascript" src="<?php echo $path ?>/js/jquery.csv.js"></script> 
<script type="text/Javascript" src="<?php echo $path ?>/js/script.js"></script> 

我可以收集的是,该插件正在尝试使用.extend将函数'csv'添加到jQuery对象,并且它不工作。有没有人看到/解决过这个问题?即时通讯假设最近有一个改变到1.5.1,但改为1.5.2并没有改变任何东西。

在此先感谢。

回答

3

使用jQuery 1.5.1在JSFiddle上正常工作。

确保您的语句被封装在'onload'块中。

jQuery(document).ready(function() { 
    ... 
    ... 
    jQuery.get(csvfile, function(data) { array = jQuery.csv()(data); }); 
}); 

另外,我看到您使用PHP来引用CSV插件文件的路径。确保PHP的路径输出仍然有效。

+0

路径是有效的,我没有检查。并且正在被调用的函数中被调用。 – psolms 2011-04-20 19:42:31

+0

虽然将插件的代码添加到onload中可以解决问题。所以那是一些东西。谢谢 :) – psolms 2011-04-20 19:43:06