This is blocked by same-origin policy.
Options:
سؤال
I'm attempting to download a CSV file through Yahoo Finance with this code.
$(function () {
$(document).ready(function() {
$.get("http://download.finance.yahoo.com/d/quotes.csv?f=snl1d1t1c1ohg&s=AAPL", function(data) {
var output = data.split(new RegExp(",|\r")).map(function (element) {
alert($.trim(element).toLowerCase());
return $.trim(element).toLowerCase();
});
});
});
});
You can see I put the alert in there (for debugging purposes) but I'm not getting the alert. Is there something wrong with this code? (some of the code was taken from how to create an array by reading text file in javascript)
Here's a jsFiddle for easy edits/help.
نصائح أخرى
Check this out with php, you can tailor make it to suit your needs.
function queryphp($url)
{
$portal = curl_init();
curl_setopt($portal, CURLOPT_URL, $url);
curl_setopt($portal, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($portal);
if(!($output))
header('Location: http://www.yourwebsite.com/errorpage.php');
curl_close($portal);
return $output;
}//example usage:
//$page_data = queryphp("http://www.whatever.com/whateverpage.php[?var1=whatever&var2=whatever"]);
//now you have the output from whateverpage.php saved as a string; which you can append anywhere to your current page's output. #repetitive code reduction