我正在尝试使用此代码通过Yahoo Finance下载CSV文件。
$(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();
});
});
});
});
你可以看到我把警报放在那里(出于调试目的),但我没有得到警报。这段代码有问题吗? (部分代码来自how to create an array by reading text file in javascript)
这是一个jsFiddle,可以轻松编辑/帮助。
答案 0 :(得分:1)
答案 1 :(得分:0)
用php检查一下,你可以根据自己的需要定制它。
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