English 中文(简体)
Error with jQuery have a CSV file
原标题:Error with jQuery get of a CSV file

Here is my relevant jQuery code:

$.get( sampleData.csv , function(data) {
    var lines = data.split( 
 );

抽样Data.csv档案的第一线类似:

2009,0,2,29.0000
2009,0,6,655.6200

I get 2 errors. On the first line of csv file I get the error

syntax误差

在代码第2行上,有错误。

资料来源:统计局。

我做了什么错误?

http://www.ohchr.org。 根据火力星群,对应器如下:

2009,0,2,29.0000 2009,... 2011,10,30,494.3500

ETA I added an alert of the data before I try splitting it into lines, and I get the following:

[目标XMLDocument]

最佳回答

我认为,你误解了哪怕是哪一种 j子,可以用来使用。

From it s doc page, "...Load data from the server using a HTTP GET request...."

在一个档案中提取一个美元,不会让你把数据输入一个可以使用的结构。 您必须通过一个服务器提出这一要求,然后提供.csv数据。

$.get( http://url.to.server.page ,function(data){
    var dataStr = new String(data);
    var lines = dataStr.split( 
 );
});

EDIT:: Since you say the data is being loaded properly, try this fiddle. It works just fine.


EDIT2::

Your last edit gave some interesting insight. When it pulls the .csv file, its converting it to a type of XML vs text. Try the following:

$.get( http://url.to.server.page ,function(data){
    var dataStr = new String(data);
    var lines = dataStr.split( 
 );
},dataType= text );

这应当将回归数据纳入适当的说明格式。

问题回答

页: 1 学历:

$.get( data.csv , function(data) {
  var lines = data.split( 
 );
});

works until jquery version 1.5.
From version 1.5 callback function in get() method is passed "jqXHR" object, not "XMLHttpRequest" object.
Code can be changed to:

$.get( data.csv , function(data) {
  var lines = data.split( 
 );
}, "text");

然后,它会发挥作用。

http://api.jquery.com/jQuery.get/a>

你们几乎在那里。 失去最后的母体,需要不同的分母。

$.get( sampleData.csv , function(data) {
var lines = data.split( , );
});

<><>Edit>/strong>

Ah 您将社保更改为两条线,即假定它只是一个线,它被 com体所割除,而不是由新线收集的数据。 下面我对我进行了测试并做了罚款。

<html>
<head>
<script type="text/javascript">Jquery Reference or insert directly here </script>
</head>
<body>
<script>
$(document).ready(function(){

    $.get( csv.csv , function(data) {
    // Split the lines
    var lines = data.split( 
 );
    var i = 0;

    for(i=0; i<lines.length; i++)
    {
       alert(lines[i]);
    }

}); 

});
</script>
</body>

</html> 

I just had that html file on my desktop with the csv you pasted in the same place.





相关问题
Styling rows in table that uses CSV data through PHP

I ve been working on this simple code that puts a CSV file into a nice table. But because the data is imported, styling ODD rows is a pretty hard thing to do. All I need would be a method to address ...

PHP - Sanitise a comma separated string

What would be the most efficient way to clean a user input that is a comma separated string made entirely on numbers - e.g 2,40,23,11,55 I use this function on a lot of my inputs function clean($...

marking duplicates in a csv file

I m stumped with a problem illustrated in the sample below: "ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, ...

Interactive heat map in Flex

I’m at a very basic level with Flex and with programming in general. I am working on a project where I have data in an Excel (.csv) format, it’s a large Excel plot/matrix where each cell has a ...

热门标签