[英]How to print variables which are on the header on javascript?
I have the following code that is not working correctly and I need to check what it is happening. 我有以下代码无法正常工作,我需要检查发生了什么。 The problem is that most of the code is done on the html header.
问题在于大多数代码是在html标头上完成的。 How can I print the variables in order to check what's wrong?
如何打印变量以检查出什么问题?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON('http://localhost/teste04.php', function(data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] // the volume
]);
}
// set the allowed units for data grouping
var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
// create the chart
chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
alignTicks: false
},
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
title: {
text: 'OHLC'
},
height: 200,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 300,
height: 100,
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
});
</script>
</head>
<body>
<script src="js/highstock.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
Edit: I would like to print "datalength" for example. 编辑:例如,我要打印“数据长度”。
Thanks in advance, Luis 预先感谢路易斯
variables inside the anonymous function you pass as parameter callback to $.getJSON only live inside it's scope. 作为参数回调传递给$ .getJSON的匿名函数内的变量仅存在于其作用域内。
You can use something like console.log(dataLength) inside that function and its value at that time will show up in the browser's console. 您可以在该函数中使用类似console.log(dataLength)之类的内容,届时其值将显示在浏览器的控制台中。
You can use a javascript debugger (firebug in firefox, Javascript Console in Chrome), set up a break point on the first line inside that function and execute it step by step to see the values in each variable. 您可以使用JavaScript调试器(firefox中的firebug,Chrome中的Javascript Console),在该函数内的第一行设置一个断点,然后逐步执行该断点以查看每个变量中的值。
Chrome, imho, has the best console and debugger, so just try this: Chrome,恕我直言,拥有最好的控制台和调试器,因此请尝试以下操作:
$.getJSON('http://localhost/teste04.php', function(data) {
console.log(data);
// split the data set into ohlc and volume
var ohlc = [],
............
hit F12 on chrome, refresh the page and whatch all the values inside the data object in the console 在chrome上按F12键,刷新页面并在控制台中获取数据对象内的所有值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.