如何在javascript上打印标题上的变量?
我有以下代码不能正常工作,我需要检查它发生了什么。问题是大部分代码都是在html头上完成的。如何打印变量以检查错误如何在javascript上打印标题上的变量?,javascript,Javascript,我有以下代码不能正常工作,我需要检查它发生了什么。问题是大部分代码都是在html头上完成的。如何打印变量以检查错误 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highstock Example</title> <script t
<!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>
Highstock示例
$(函数(){
$.getJSON('http://localhost/teste04.php,函数(数据){
//将数据集拆分为ohlc和卷
var ohlc=[],
卷=[],
dataLength=data.length;
对于(i=0;i
编辑:例如,我想打印“datalength”
提前感谢,,
作为参数回调传递给$.getJSON的匿名函数中的Luis变量仅在其作用域内活动。
您可以在该函数中使用类似于console.log(dataLength)的内容,此时它的值将显示在浏览器的控制台中。
您可以使用javascript调试器(firefox中的firebug,Chrome中的javascript控制台),在该函数的第一行上设置一个断点,然后一步一步地执行它以查看每个变量中的值 Chrome,imho,有最好的控制台和调试器,所以试试这个:
$.getJSON('http://localhost/teste04.php', function(data) {
console.log(data);
// split the data set into ohlc and volume
var ohlc = [],
............
在chrome上点击F12,刷新页面,然后在控制台中对数据对象中的所有值进行匹配您想打印什么“变量”第21行缺少分号
volume.push([data[i][0],//日期数据[i][5]//卷])代码>添加了分号,变量可以是“datalength”,谢谢,因为它起作用了。问题似乎是在getJSON中我无法让它运行。。。像这样它工作:$(function(){console.log(“1”);$.getJSON('teste04.php',function(data){像这样它不工作[17:59:18.597]获取[HTTP/1.1200ok 1606ms]$(function(){$.getJSON('teste04.php',function(data){//将数据集拆分为ohlc和volume console.log(“1”);没有任何错误…这里有些问题,因为如果AJAX调用正确,匿名函数将被执行并接收参数数据,因此您必须能够控制台记录它。问题似乎出在getJSON上,我无法使其工作。我将创建一个新问题,看看我是否能够使其工作。感谢teste04.php没有返回正确的数据,您应该执行header('Content-type:application/json');echo json_encode($yourdata);好了,问题解决了,我在json_encode上有一个错误……感谢您的帮助。