未捕获的TypeError:Cannpt读取未定义的属性'columnHeaders' [英] Uncaught TypeError: Cannpt read property 'columnHeaders' of undefined
问题描述
大家好,
我对AJAX和JavaScript有疑问。
我是使用下面的AJAX函数使用JSON Web服务生成JSON对象。
*** AJAX函数***
Hi All,
I have a question regarding AJAX and JavaScript.
I'm using an AJAX function that is in the below to generate a JSON object using an JSON Web service.
***AJAX Function***
function setJsonSer() {
var strWsUrl = 'https://www.googleapis.com/analytics/v3/data/ga?
ids=ga%3A76546294&dimensions='+ 'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-
date='+retStartDate()+'&end-date='+retEndDate()+'&max-results=10';
formData = {
'Email': 'clientlink@client.com',
'Password': 'password',
'URL': strWsUrl
};
$.ajax({
url: "/APIWebService.asmx/AnalyticsDataShowWithPost",
type: 'POST',
data: formData,
complete: function(data) {
var responseText = data.responseText;
var responseJson = JSON.parse(responseText.match(/[{].*.[}]/));
/*01*/ console.log("'responseJson' is " + typeof responseJson );
alert(JSON.stringify(responseJson)); //or just `responseJson` if you skip
`JSON.parse`*/
/*04*/ Load(JSON.stringify(responseJson));
}
});
}
这样JSON对象就会被传递给另一个JavaScript函数。它在下面。
*** JavaScript功能***
So that JSON object will be passed to another JavaScript Function. It's in the below.
***JavaScript Function***
function Load(responseJson){
setJsonSer();
//----------------------------------------------- Rohan
var labels = new Array();
var values = new Array();
var catogories = new Array();
var arrayOfArray = new Array();
var rowData = responseJson;
/*02*/console.log("'RowData' is " + typeof rowData );
var inData = responseJson;
/*03*/console.log("'inData' is " + typeof rowData );
var count = 0;
/*05*/var headers = new Array();
for (var i = 0; i < inData.columnHeaders.length; i++) {
headers[i] = inData.columnHeaders[i].name;
}
var dates = new Array();
var pageViews = new Array();
var uniqueViews = new Array();
for (var key in inData.rows) {
pageViews[key] = parseInt(inData.rows[key][1]);
uniqueViews[key] = parseInt(inData.rows[key][2]);
}
$('#container_2').highcharts({
chart: {
type: 'areaspline', zoomType: 'x'
},
title: {
text: 'Pageviews and Bounces'
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 150,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
xAxis: {
categories: dates,
type: 'datetime',
dateTimeLabelFormats: {
month: '%d %b',
},
tickInterval: 10,
plotBands: [{ // visualize the weekend
color: 'rgba(68, 170, 213, .2)'
}]
},
yAxis: {
title: {
text: 'Visits'
}
},
tooltip: {
shared: true,
valueSuffix: ' '
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'Page Views',
data: pageViews
}, {
name: 'Bounces',
data: uniqueViews
}]
});
}
在/ * 05 * /我收到错误提示Uncaught TypeError:Cannpt读取未定义的属性'columnHeaders'。所以我做错了就做错了。你能帮助我解决这个问题吗?
谢谢和问候,
Chiranthaka
In the /*05*/ I got an error saying "Uncaught TypeError: Cannpt read property 'columnHeaders' of undefined". So what I have done wrong to have such an error. Could you please someone help me to solve this matter?
Thanks and regards,
Chiranthaka
推荐答案
.ajax({
url: / APIWebService.asmx / AnalyticsDataShowWithPost,
类型:' POST',
data:formData,
complete: function (data){
var responseText = data.responseText;
var responseJson = JSON .parse(responseText.match(/ [{ ]。*。[}] /));
/ * 01 * / console .log( 'responseJson'是 + typeof responseJson);
alert( JSON .stringify(responseJson)); // 或者只是`responseJson`如果你跳过
` JSON.parse` * /
/ * 04 * / Load(JSON.stringify(responseJson));
}
});
}
.ajax({ url: "/APIWebService.asmx/AnalyticsDataShowWithPost", type: 'POST', data: formData, complete: function(data) { var responseText = data.responseText; var responseJson = JSON.parse(responseText.match(/[{].*.[}]/)); /*01*/ console.log("'responseJson' is " + typeof responseJson ); alert(JSON.stringify(responseJson)); //or just `responseJson` if you skip `JSON.parse`*/ /*04*/ Load(JSON.stringify(responseJson)); } }); }
这样JSON对象就会被传递给另一个JavaScript函数。它在下面。
*** JavaScript功能***
So that JSON object will be passed to another JavaScript Function. It's in the below.
***JavaScript Function***
function Load(responseJson){
setJsonSer();
//----------------------------------------------- Rohan
var labels = new Array();
var values = new Array();
var catogories = new Array();
var arrayOfArray = new Array();
var rowData = responseJson;
/*02*/console.log("'RowData' is " + typeof rowData );
var inData = responseJson;
/*03*/console.log("'inData' is " + typeof rowData );
var count = 0;
/*05*/var headers = new Array();
for (var i = 0; i < inData.columnHeaders.length; i++) {
headers[i] = inData.columnHeaders[i].name;
}
var dates = new Array();
var pageViews = new Array();
var uniqueViews = new Array();
for (var key in inData.rows) {
pageViews[key] = parseInt(inData.rows[key][1]);
uniqueViews[key] = parseInt(inData.rows[key][2]);
}
(' #container_2')。highcharts({
chart:{
type:' areaspline',zoomType:' x'
},
title:{
text:' 浏览量和跳出次数
},
图例: {
layout:' vertical',
align:' left',
verticalAlign:' top',
x: 150 ,
y: 100 ,
浮动: true ,
borderWidth: 1 ,
backgroundColor:(Highcharts.theme&& Highcharts.theme.legendBackgroundColor)|| ' #FFFFFF'
},
xAxis:{
categories :日期,
类型:' datetime',
dateTimeLabelFormats:{
月:' %d%b',
},
tickInterval : 10 ,
plotBands:[{ // 可视化周末
颜色:' rgba(68,170,213) ,.2)'
}]
},
yAxis:{
title:{
text:' 访问次数
}
},
工具提示:{
shared: true ,
valueSuffix:' '
},
credits:{
enabled: false
},
plotOptions:{
areaspline:{
fillOpacity: 0 。 5
}
},
系列:[{
name:' Page Views' ,
数据:pageViews
},{
name:' Bounces',
data:uniqueViews
}]
});
}
('#container_2').highcharts({ chart: { type: 'areaspline', zoomType: 'x' }, title: { text: 'Pageviews and Bounces' }, legend: { layout: 'vertical', align: 'left', verticalAlign: 'top', x: 150, y: 100, floating: true, borderWidth: 1, backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF' }, xAxis: { categories: dates, type: 'datetime', dateTimeLabelFormats: { month: '%d %b', }, tickInterval: 10, plotBands: [{ // visualize the weekend color: 'rgba(68, 170, 213, .2)' }] }, yAxis: { title: { text: 'Visits' } }, tooltip: { shared: true, valueSuffix: ' ' }, credits: { enabled: false }, plotOptions: { areaspline: { fillOpacity: 0.5 } }, series: [{ name: 'Page Views', data: pageViews }, { name: 'Bounces', data: uniqueViews }] }); }
在/ * 05 * /我收到错误提示Uncaught TypeError:Cannpt读取未定义的属性'columnHeaders'。所以我做错了就做错了。你有没有人可以帮我解决这个问题?
谢谢和问候,
Chiranthaka
In the /*05*/ I got an error saying "Uncaught TypeError: Cannpt read property 'columnHeaders' of undefined". So what I have done wrong to have such an error. Could you please someone help me to solve this matter?
Thanks and regards,
Chiranthaka
你可以尝试在你的ajax中使用错误部分。我猜这个阶段会抛出错误。
如果可能的话,分享完整的代码,包括retEndDate和retStartDate函数
can u try using error section in your ajax. I guess the error thrown at this stage.
If possible share the complete code including retEndDate and retStartDate functions
这篇关于未捕获的TypeError:Cannpt读取未定义的属性'columnHeaders'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!