i'm trying to download a csv file from a online realtime data source using javascript but the link of the source is not a direct link CSV SOURCE so i hope some one quite give a good exmaple or source that i could follow and also some example on using a loop to decoded the csv using javascript
Thanks in advance
Update
Thanks guys i have managed to do some research from the link that you all gave me but there is one problem i cant seem to solve the No 'Access-Control-Allow-Origin' header is present on the requested resource
. so could i request some help in this
$("#postdata").click(function()
{
csvData = $.ajax({
headers: { 'Access-Control-Allow-Origin': '*'},
Accept : "text/csv; charset=utf-8",
url:"https://www.emcsg.com/marketdata/priceinformation",
data:"downloadRealtime=true&5Periods=true",
type:"GET",
crossDomain: true,
dataType:"text/csv",
success: function (result) {
alert(result);
alert("done!"+ csvData.getAllResponseHeaders())
},
error:function(jqXHR,textStatus,errorThrown)
{
alert("You can not send Cross Domain AJAX requests: "+errorThrown);
}
});
Thanks once again
Updated Problem solve turn out the website does not allow cors i switch to php here the code
<?php
$file= file_get_contents("https://www.emcsg.com/marketdata/priceinformation?downloadRealtime=true&5Periods=true");
$array = array_map("str_getcsv", explode("\n", $file));
print json_encode($array);
?>