"Can you please elaborate on Ajax method to upload a file to server
and echo it back as that is what i am looking at so that i dont cause
any Security issues." -user428747
Given a .csv
file , e.g., from Wikipedia - Comma-separated values - Example
csv
Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00
html
<pre></pre>
js
$(function () {
var url = "file.csv";
$.getJSON("https://query.yahooapis.com/v1/public/yql?q=select"
+ "* from csv where url='" + url + "?'"
+ "&format=json&diagnostics=true&callback=?")
.then(function (data, textStatus, jqxhr) {
var arr = [];
var len = data.query.count;
$.each(data.query.results.row, function (k, v) {
$.map(v, function (val) {
if (val === null) {
val = '""';
};
arr.push(val)
});
});
var rebuild_csv = function () {
$.when(
$("pre")
.append(
arr.splice(0, len).join(",") + "\r\n"))
.done(function () {
if (arr.length) {
rebuild_csv()
};
});
};
rebuild_csv();
}, function (jqxhr, textStatus, errorThrown) {
console.log(textStatus, errorThrown)
});
});
jsfiddle http://jsfiddle.net/guest271314/2oLmxb0g/
See , also How to get attachment file content with jQuery