jQuery美元符号是未定义的 [英] jQuery dollar sign is undefined
问题描述
在追求历史信息的过程中,我尝试使用下面的代码。 Chrome调试器说 Uncaught ReferenceError:$未定义
。你能提出一个解决方案,我真的卡住了。我只是需要这个工作在Chrome上,而我正在利用YQL和雅虎API。
这里是jsFiddle http://jsfiddle.net/pCK5q/1/
< HTML>
< head>
< script type ='text / javascript'src ='http://www.google.com/jsapi'>< / script>
< script type ='text / javascript'>
google.load('visualization','1',{'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);
函数drawChart(){
var data = new google.visualization.DataTable();
/ *破解的历史数据代码* /
var url ='http://query.yahooapis.com/v1/public/yql';
var startDate ='2012-01-01';
var endDate ='2012-01-08';
var jsonData = encodeURIComponent('select * from yahoo.finance.historicaldata where(YHOO,AAPL,GOOG,MSFT)and startDate ='+ startDate +'和endDate ='+ endDate +'');
$ .getJSON(url,'q ='+ data +& env = http%3A%2F%2Fdatatables.org%2Falltables.env& format = json,callback);
data.addColumn('date','Date');
data.addColumn('数字','已售铅笔');
data.addColumn('string','title1');
data.addColumn('string','text1');
data.addColumn('number','卖笔');
data.addColumn('string','title2');
data.addColumn('string','text2'); //不是实时的
data.addRows([
[new Date(2008,1,1),30000,undefined,undefined,40645,undefined,undefined] ,
[new Date(2008,1,2),14045,undefined,undefined,20374,undefined,undefined],
[new Date(2008,1,3),55022,undefined,undefined, 50766,undefined,undefined],
[new Date(2008,1,4),75284,undefined,undefined,14334,'Out of Stock','Ran out of stock at pen at 4pm'],
[new Date(2008,1,5),41476,'Bought Pens','买200k笔',66467,undefined,undefined],
[new Date(2008,1,6),33322, undefined,undefined,39463,undefined,undefined]
]);
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data,{displayAnnotations:true});
}
< / script>
< / head>
< body>
//注意您必须明确指定容器元素的大小!
< div id ='chart_div'style ='width:700px; height:240px;'>< / div>
< / body>
添加以下行:
google.load(jquery,1.7.1);
就在这个下面你已经有了:
google.load('visualization','1',{'packages':['annotatedtimeline']});
这会从您已经使用的Google jsapi中加载jQuery。这是关于您的代码的最佳解决方案。
In my quest to get historical information, i tried using the below code. Chrome debugger says that Uncaught ReferenceError: $ is not defined
. Can you suggest a fix, i'm really stuck. I just need this to work on Chrome, and I am tapping into YQL and Yahoo API.
here is the jsFiddle http://jsfiddle.net/pCK5q/1/
<html>
<head>
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
/* historical data code that breaks */
var url = 'http://query.yahooapis.com/v1/public/yql';
var startDate = '2012-01-01';
var endDate = '2012-01-08';
var jsonData = encodeURIComponent('select * from yahoo.finance.historicaldata where symbol in ("YHOO","AAPL","GOOG","MSFT") and startDate = "' + startDate + '" and endDate = "' + endDate + '"');
$.getJSON(url, 'q=' + data + "&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json", callback);
data.addColumn('date', 'Date');
data.addColumn('number', 'Sold Pencils');
data.addColumn('string', 'title1');
data.addColumn('string', 'text1');
data.addColumn('number', 'Sold Pens');
data.addColumn('string', 'title2');
data.addColumn('string', 'text2'); // not on the fly
data.addRows([
[new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
[new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
[new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined],
[new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'],
[new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined],
[new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined]
]);
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data, {displayAnnotations: true});
}
</script>
</head>
<body>
// Note how you must specify the size of the container element explicitly!
<div id='chart_div' style='width: 700px; height: 240px;'></div>
</body>
Add this line:
google.load("jquery", "1.7.1");
Just under this one you already have:
google.load('visualization', '1', {'packages':['annotatedtimeline']});
This will load jQuery from the Google jsapi you already use. This is the best solution regarding your code.
这篇关于jQuery美元符号是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!