0

修复了代码无法运行的初始问题。似乎无法确定在这篇文章底部引发错误的位置或段。

用户可以单击链接并启动 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
4

1 回答 1

0

使用src属性而不是 AJAX 来延迟加载HighCharts,将其别名jQuery为属性,然后调用依赖代码:

var jqScript = document.getElementsByTagName('script')[0];
var hcScript = document.createElement('script');
hcScript.src = "http://code.highcharts.com/highcharts.js";

document.documentElement.insertBefore(hcScript, jqScript);

hcScript.onload = function () {
  $.highcharts = HighCharts;
  dothis();
};
于 2013-10-10T01:48:16.630 回答