I have a CSV which I need to display on a page. I can do this via $.get() but once I have the (data) how can I separate it and allocate where to display it. Each line is separated by a |
Currently I’m using this code to display the info in a div:
$.get('feed.txt', function(data) {
$('div').html(data.replace(/\|/g, '<br>'));
});
I know this is probably a very big question to ask, so if anyone has encountered a good tutorial that would be awesome too.
UPDATE
Here is an example of the data I’m pulling in:
TYPE: Small, ID: 0001, RESPONSE DATE AND TIME: 2012-12-12 12:00, UNITNAME: Name, MEMO: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.|
TYPE: Medium, ID: 0002, RESPONSE DATE AND TIME: 2012-12-12 01:00, UNITNAME: Name, MEMO: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.|
TYPE: Large, ID: 0003, RESPONSE DATE AND TIME: 2012-12-12 02:00, UNITNAME: Name, MEMO : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.|
You can try,
Try 1:
I used
split()to convert string to array delimited by|and loop each array value to adddivelement and send it to$('div').html(values);Demo: http://jsfiddle.net/d3spZ/2/
Try 2:
Here I used
replace()function to warpdivelements by replacing|.Demo: http://jsfiddle.net/bwpjR/