0
修復了代碼無法運行的初始問題。看起來似乎無法確定位置或細分在本文底部拋出錯誤。用ajax調用Highcharts的函數?
用戶可以點擊鏈接並啓動ajax調用。如果ajax調用不存在,則將以下源代碼嵌入頁面的頭部,然後調用dothis函數。當電話通知getlegislators(uid)時,問題就出現了。
$('#votescode').ready(function() {
function dothis(){
Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
return {
radialGradient: { cx: 0.4, cy: 0.2, r: 0.7
},
stops: [
[0, color],
[1, Highcharts.Color(color).brighten(-0.3).get('rgb')]
]
};
});
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
size: 200,
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
credits:{enabled:false},
exporting:{enabled:false},
colors:['#ADD46D','#F1744F','#b9e376','#f2a48d'],
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Supports You', 1.0],
['Opposes You', 1.0],
['Absent on Supporting', 0.0],
['Absent on Opposing', 0.0]
]
}]
});
}
dothis();
});
這裏的ajax.js的副本是在用戶點擊啓動:
function getXMLHttp()
{
var xmlHttp
try
{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
function getcmtename(chamb){
var xmlHttp = getXMLHttp();
var idid = 'waiting';
toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "ajax.php?chamb="+chamb+"&n="+Math.random(), true);
xmlHttp.send(null);
}
function MakeRequest(iorf)
{
var xmlHttp = getXMLHttp();
var idid = 'waiting';
toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "ajax.php?req="+iorf+"&n="+Math.random(), true);
xmlHttp.send(null);
}
function getsch(iorf)
{
var xmlHttp2 = getXMLHttp();
var idid = 'waiting';
toggle_visibility(idid);
xmlHttp2.onreadystatechange = function()
{
if(xmlHttp2.readyState == 4)
{
HandleResponse5(xmlHttp2.responseText);
}
}
xmlHttp2.open("GET", "ajax.php?p=comm&chamb="+iorf+"&n="+Math.random(), true);
xmlHttp2.send(null);
}
function getfloorvotes(rcnum,type,syr,sind,chamb){
if(document.getElementById("votescode")){
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse2(xmlHttp.responseText);
//BELOW GENERATES CHART CODE
var xmlHttp2 = getXMLHttp();
xmlHttp2.onreadystatechange = function()
{
if(xmlHttp2.readyState == 4)
{
HandleResponse4(xmlHttp2.responseText);
dothis();
}
}
xmlHttp2.open("GET", "billajax.php?&p=vc&chamb="+chamb+"&type="+type+"&syr="+syr+"&sid="+sind+"&rcnum="+rcnum+"&n="+Math.random(), true);
xmlHttp2.send(null);
}
}
xmlHttp.open("GET", "billajax.php?&p=bvotes&chamb="+chamb+"&type="+type+"&syr="+syr+"&sid="+sind+"&rcnum="+rcnum+"&n="+Math.random(), true);
xmlHttp.send(null);
}else{
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse2(xmlHttp.responseText);
//BELOW GENERATES CHART CODE
var xmlHttp2 = getXMLHttp();
xmlHttp2.onreadystatechange = function()
{
if(xmlHttp2.readyState == 4)
{
HandleResponse3(xmlHttp2.responseText);
dothis();
}
}
xmlHttp2.open("GET", "billajax.php?&p=vc&chamb="+chamb+"&type="+type+"&syr="+syr+"&sid="+sind+"&rcnum="+rcnum+"&n="+Math.random(), true);
xmlHttp2.send(null);
}
}
xmlHttp.open("GET", "billajax.php?&p=bvotes&chamb="+chamb+"&type="+type+"&syr="+syr+"&sid="+sind+"&rcnum="+rcnum+"&n="+Math.random(), true);
xmlHttp.send(null);
}
}
function getlegislators(uid){
if(document.getElementById("votescode")){
var xmlHttp = getXMLHttp();
var idid = 'waiting';
//toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse10(xmlHttp.responseText);
var xmlHttp2 = getXMLHttp();
xmlHttp2.onreadystatechange = function()
{
if(xmlHttp2.readyState == 4)
{
HandleResponse11(xmlHttp2.responseText);
dothis();
dothis2();
}
}
xmlHttp2.open("GET", "ajax.php?&p=glv&req="+uid+"&n="+Math.random(), true);
xmlHttp2.send(null);
}
}
xmlHttp.open("GET", "ajax.php?p=gl&req="+uid+"&n="+Math.random(), true);
xmlHttp.send(null);
}else{
var xmlHttp = getXMLHttp();
var idid = 'waiting';
//toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse10(xmlHttp.responseText);
var xmlHttp2 = getXMLHttp();
xmlHttp2.onreadystatechange = function()
{
if(xmlHttp2.readyState == 4)
{
HandleResponse12(xmlHttp2.responseText);
dothis();
dothis2();
}
}
xmlHttp2.open("GET", "ajax.php?&p=glv&req="+uid+"&n="+Math.random(), true);
xmlHttp2.send(null);
}
}
xmlHttp.open("GET", "ajax.php?p=gl&req="+uid+"&n="+Math.random(), true);
xmlHttp.send(null);
}
}
function gettracks(uid){
var xmlHttp = getXMLHttp();
var idid = 'waiting';
//toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse10(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "ajax.php?p=gt&req="+uid+"&n="+Math.random(), true);
xmlHttp.send(null);
}
function getMembers(iorf)
{
var xmlHttp = getXMLHttp();
var idid = 'waiting';
toggle_visibility(idid);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "ajax.php?p=l&req="+iorf+"&n="+Math.random(), true);
xmlHttp.send(null);
}
function HandleResponse(response)
{
var idid = 'waiting';
toggle_visibility(idid);
document.getElementById('selissues').innerHTML = response;
var shn = $('.shtn').ThreeDots();
shn.ThreeDots.update({max_rows:1});
}
function HandleResponse10(response)
{
var idid = 'waiting';
//toggle_visibility(idid);
document.getElementById('initiative').innerHTML = response;
//var shn = $('.shtn').ThreeDots();
//shn.ThreeDots.update({max_rows:1});
}
function HandleResponse5(response2)
{
var idid = 'waiting';
toggle_visibility(idid);
document.getElementById('org_activity').innerHTML = response2;
var shn = $('.shtn').ThreeDots();
shn.ThreeDots.update({max_rows:1});
}
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
function HandleResponse2(response)
{
//var idid = 'waiting';
//toggle_visibility(idid);
document.getElementById('billinfor').innerHTML = response;
//var shn = $('.shtn').ThreeDots();
//shn.ThreeDots.update({max_rows:1});
var bsy = $('.billsy').ThreeDots();
bsy.ThreeDots.update({max_rows:3});
}
function HandleResponse3(response)
{
//var idid = 'waiting';
//toggle_visibility(idid);
var script = document.createElement("script");
script.setAttribute("id", "votescode");
script.innerHTML = response;
document.head.appendChild(script);
}
function HandleResponse4(response)
{
//var idid = 'waiting';
//toggle_visibility(idid);
var el = document.getElementById('votescode');
el.parentNode.removeChild(el);
var script = document.createElement("script");
script.setAttribute("id", "votescode");
script.innerHTML = response;
document.head.appendChild(script);
}
function HandleResponse11(response)
{
//var idid = 'waiting';
//toggle_visibility(idid);
var el = document.getElementById('votescode');
el.parentNode.removeChild(el);
var script = document.createElement("script");
script.setAttribute("id", "votescode");
script.innerHTML = response;
document.head.appendChild(script);
}
function HandleResponse12(response)
{
//var idid = 'waiting';
//toggle_visibility(idid);
var script = document.createElement("script");
script.setAttribute("id", "votescode");
script.innerHTML = response;
document.head.appendChild(script);
}
這裏是錯誤的,從瀏覽器的控制檯的摘錄。
Uncaught TypeError: Object [object Object] has no method 'ThreeDots' index.php:129
makesmalll index.php:129
fire jquery-1.9.1.js:1037
self.fireWith jquery-1.9.1.js:1148
jQuery.extend.ready jquery-1.9.1.js:433
completed
Uncaught TypeError: Object [object Object] has no method 'highcharts'
dothis
(anonymous function)
o jquery.min.js:2
p.add jquery.min.js:2
e.fn.e.ready jquery.min.js:2
(anonymous function)
HandleResponse12 ajax.js:317
xmlHttp2.onreadystatechange ajax.js:184
Uncaught ReferenceError: dothis is not defined ajax.js:185
xmlHttp2.onreadystatechange
你給highchart JS的參考? – rach
您需要在所有內容加載完成後調用此函數,即使用jQuery的'ready'方法。在jsfiddle上,從左側的保存箱中選擇「onDomready」,它將起作用,這是等同的。 –
當然,jsfiddle不會運行,並且在其他頁面上也可以正常工作。 – user2355051