Answered Sidebar Refresh error

  • Friday, July 06, 2012 12:24 PM
     
      Has Code

    Hello All,

    I'm trying to get my sidebar to pull data every four hours from a server; the error I keep getting is the Breaking on JScript runtime error -- Object doesn't support this property or method. I've been setting the interval onload. It then executes the data pull/parsing/deploying. Once the initial deployment is done, I get an error on the first interval and the gadget never refreshes. Any help, clarification would be appreciated.

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
        <!--  <meta http-equiv="refresh" content="14400" />   -->
        <link rel="stylesheet" type="text/css" href="test.css" />
        <script type = "text/javascript" src = "jquery-1.7.2.js"></script><!-- this pulls the jquery scripting language -->
        <script type="text/javaScript" src="flyout.js"></script>
        <script type="text/jscript">
            // Initialize the gadget.
            function init() {
                var oBackground = document.getElementById("imgBackground");
                oBackground.src = "url(images/background2.png)";
                csvOne();
                tableOne();
                dlypyr();
                dlyin();            
            }
    </script>
    
        <script type="text/javascript">
    
            function run() {
                window.setInterval('init()', 100);
            }
    
            var oneRow = new Array();
            var oneData = new Array();
            var oneLen = '';
    
            function csvOne() {
                csvOne = new XMLHttpRequest();
                csvOne.open("GET", "http://tennfrthgps04/DailypayorTotal.csv", false);
                csvOne.onreadystatechange = checkOne;
                csvOne.send();            
            }//end csvOne
    
            function checkOne() {
                if (csvOne.readyState == 4) {
                    if (csvOne.status == 200) {
                        tableOne(csvOne.responseText);
                    }//ends status
                }//ends readyState
            }//end checkOne
    
            function tableOne() {
                oneText = csvOne.responseText;
                oneRow = oneText.split("\n");
                oneLen = oneRow.length;
                for (var i = 0; i < oneLen; i++) { // this creates loop for splitting allTextLines[i] array
                    var oneData = oneRow[i].split(","); //this creates split on each array line
                    var dataLen = oneRow[i].split(",").length;//this determines length for this [i] split for variable
                    oneRow[i] = new Array(dataLen); //this creates new array limited to length of elements in L2
                    for (var j = 0; j < dataLen; j++) { //this creates loop for splitting [i] into each position
                        oneRow[i][j] = oneData[j]; //this provides reference location for [i][j] sub array value
                    }// ends for j
                }//ends for i
            }//end tableOne
    
            function dlypyr() {
                var table = '<table class =\'dlypyr\'>';
                //table += '<a href=\'javascript:void(0);\' onclick=\'showFlyout();\'>';
                table += '<caption class = \'caption\'>Daily Payor</caption>';
                table += '<tr class = \'header\'>';
                table += '<th> Payor Summary </th>';
                for (l = 0; l < oneRow[0].length; l++) {
                    table += '<th>' + oneRow[0][l] + '</th>';
                }//end l
                table += '</tr><tr>';
                table += '<td>Total</td>';
                var n = oneLen - 2;
                for (m = 0; m < oneRow[0].length; m++) {
                    table += '<td>' + oneRow[n][m] + '</td>';
                }//end m
                table += '</tr>';
                table += '</table><br />';
                table += '<a class=\'link\' href=\'javascript:void(0);\' onclick=\'showFlyout();\'>'
                table += 'Click here for Detail</a>';
                $("#dlypyr").html(table);
            }//end dlypyr2
    
        </script>

All Replies

  • Friday, July 06, 2012 8:04 PM
     
     Answered

    Well, I''l try to to have a look tomorrow but it seems kinda strange that you have an undeclared global called csvOne ( csvOne = new XMLHttpRequest(); ) - as well as a function called csvOne. You might try changing either one. And declaring the global.

    Also there is no need to have two scripts - one javascript and the other jscript. Just put it all between the one set of script tags and either type declaration (javascript or jscript) will work.

    Is there a reason you need to send requests ten times a second ?

    ......

    Rats, put my head on the pillow, tried to go to sleep and...

    If you really do need to send that many requests then you will probably be better off using setTimeout rather than setInterval. 

    The former runs at a set time after the completion of the last cycle while the latter runs at a set time regardless of whether the last cycle has finished.

    • Edited by mystifeid Friday, July 06, 2012 8:21 PM
    • Marked As Answer by Patrick Justice Monday, July 09, 2012 2:55 PM
    •  
  • Saturday, July 07, 2012 7:46 PM
     
      Has Code

    Made an example and the problem definitely seems to be the duplication of the name between the variable and the function ("csvOne"). If you change either one it will probably work. When the name is duplicated in the example below the gadget locks up in error after the first request.

    But there may be a few other things that are causing problems.

    You would be better off putting everything you want to do with the response text inside the onreadystatechange function. That would include the contents of functions tableOne and dlypyr. Then use setInterval to repeat the function that is sending the request, not the one that is also setting the background image - unless of course you are going to change the image.

    Please don't use string evals in setInterval and setTimeout - use function pointers (see example below). No quotation marks, no brackets, just the function name.

    Are you using jQuery for more than just the one line ? If so you can easily rewrite this line without jQuery and save having to load a whole lot of extra javascript.

    Also it may not be necessary to rewrite the entire table in function dlypyr ten times a second. 

    So, here's the fun little toy. Lurid colors.

    Just put a url in the appropriate place.

    I have a simple script that returns a gadget version number when the url is requested and this can be seen in the image. Running the setInterval at ten times a second with just this simple response text generated around 2.5 kbytes/sec download. When I used a simple web page instead it generated a constant 75 kbytes/sec download.

    It would be a good idea not to aim this gadget as it stands at anyones servers but your own.

                                

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Hello World</title> <style type="text/css"> <!-- body {margin:0;width:130px;height:170px;background-color:#F9B11C;padding:5px;font:12px/14px "Segoe UI";text-align:center;color:#000;} #infoBox, #rqst {width:114px;height:30px;margin:5px 0;padding-top:9px;overflow:hidden;} #infoBox {background-color:07f;} #rqst {background-color:cc0;} #strt, #stp {width:114px;height:20px;margin-top:6px;padding:2px 0;border:2px solid #000;cursor:pointer;} --> </style> <script type="text/jscript"> var t=null; var responses=0; function reLoad(){ var xmlHttp=new XMLHttpRequest(), myUrl="[Put your URL here]"; xmlHttp.open("GET", myUrl, false); xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState===4){ if(xmlHttp.status===200){ infoBox.innerText=xmlHttp.responseText; responses++; rqst.innerText=responses; xmlHttp=null; } } }; xmlHttp.send(); } //try changing the name of function reLoad above to xmlHttp and uncommenting the function below //and after the first request is sent the error will lock up the gadget. /* function reLoad(){ xmlHttp(); } */ function fx(){ strt.onclick=function(){if(t===null){responses=0;t=setInterval(reLoad,100);}}; stp.onclick=function(){clearInterval(t);t=null;}; } </script> </head> <body onload="fx();"> Response Text <div id="infoBox"></div> Request Number <div id="rqst"></div> <div id="strt">Click to Start</div> <div id="stp">Click to Stop</div> </body>




    • Edited by mystifeid Saturday, July 07, 2012 7:54 PM
    •  
  • Monday, July 09, 2012 12:09 PM
     
     

    Mystified,

    Sorry for not responding earlier, busy unpacking and no network connection yet at the house.

    re: scripts. Thought you needed to declare both type of scripts in order for it to work if they're separate. I've removed the type code.

    re: 10 times a second. That was just so I could test for the error response. It needs to run every four hours and I'll adjust once I've confirmed I'm getting the program running correctly.

    re: duplicate names. That seems to have been the issue. I didn't realize that would cause that issue. I'm no longer seeing a scripting error but the data isn't being updated in the browser. Is there a way to clear the cache in IE so it will refresh each time the data is pulled?

    edit: added ?random=" + Math.random()*1000 to the end of my URL and it is now refreshing. It ignores that random # at the end and pulls the correct csv file.

    Thank you again for the help,

    Patrick


    • Edited by Patrick Justice Monday, July 09, 2012 12:47 PM found answer for additional refresh other location.
    •  
  • Monday, July 09, 2012 12:38 PM
     
     

    re: calling function in readystatechange. Good point - I separated the functions to isolate each function. More of a control for my new programming skills and I agree that its more elegant to call the functions as you describe.

    re: string evals. I've read how 'evals = evil',  just didn't realize I had done that there until you pointed it out. Simple change and done.

    re: jquery. The initial roll out will not be taking advantage fully of jquery, the flyouts will have additional functionality for the user that will take advantage of some jquery scripting functions.

    Patrick

  • Monday, July 09, 2012 2:44 PM
     
     

    No worries. (I'd forgotten that I had IE set to check for 'newer versions of stored pages' every time. And each time I do this it makes me think this other gadget is broken. I think : why is it checking? Why isn't it using cache ? You'd think I'd remember by now.)

     

    Good luck



    • Edited by mystifeid Monday, July 09, 2012 3:03 PM
    •