Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/06/2012, 09:29
merchell
 
Fecha de Ingreso: marzo-2012
Mensajes: 28
Antigüedad: 12 años, 1 mes
Puntos: 1
Exclamación Problema Variable Global

Tengo un pequeño gran problema en mi codigo tengo declaradas 3 variables globales que se les va asignando valores en distintas funciones, en teoria deberia poder utilizar su contenido en cualquier funcion debido a que son globales, pero el intentar usarlas no contienen ningun valor.

Este es mi codigo

Código HTML:
<script type="text/javascript">
           var v=[];
            var v2=[];
            var dia=[];
            
           function recibe(name){
                var regexS = "[\\?&]"+name+"=([^&#]*)";
                var regex = new RegExp ( regexS );
                var tmpURL = window.location.href;
                var results = regex.exec( tmpURL );
                if( results == null )
    		        return "";
    	        else
    		        return results[1];
            }
           
            function callTheJsonp()
            {
                var reci=recibe('periodo');
                var url = "http://www.trueware.mx/eduardo/mycommerce/ventadiaria.php?callback=parseRequest&periodo="+reci;
                var script = document.createElement('script');
                script.setAttribute('src', url);
                document.getElementsByTagName('head')[0].appendChild(script);
            }
           
           function parseRequest(response)
            {
                try
                {
                    console.log(response);
                    var venta=[];
                    var prod=[];
                    var acum=0;
    				for (var i=0; i < response.length; i++) 
                    {
						venta[i] = eval(response[i].venta);
                        prod[i] = eval(response[i].dia);
                        acum=acum+venta[i]; 
					}
                    for(var i=0; i < 32; i++)
                    {
                        v[i]=0;
                        dia[i]=i;
                    }
                    for (var i=0; i < prod.length; i++) 
                    {
                        v[prod[i]]=venta[i];
                    }
                    var li = document.createElement("LI");
                    li.innerHTML = '<font size=2>'+'Venta Total: '+acum+'</font>';
                    var ul = document.getElementById("contenido");
                    ul.appendChild(li);
                }
                catch(an_exception)
                {
                    document.write("Error de Conexion");
                }
            }
            function callTheJsonp2()
            {
                var reci=recibe('periodo');
                var url = "http://www.trueware.mx/eduardo/mycommerce/ventadiaria12.php?callback=parseRequest2&periodo="+reci;
                var script = document.createElement('script');
                script.setAttribute('src', url);
                document.getElementsByTagName('head')[0].appendChild(script);
            }
           
           function parseRequest2(response)
            {
                try
                {
                    console.log(response);
                    var venta=[];
                    var prod=[];
        			for (var i=0; i < response.length; i++) 
                    {
						venta[i] = eval(response[i].venta);
                        prod[i] = eval(response[i].dia);
					}
                    for(var i=0; i < 32; i++)
                    {
                        v2[i]=0;
                    }
                    for (var i=0; i < prod.length; i++) 
                    {
                        v2[prod[i]]=venta[i];
                    }
                }
                catch(an_exception)
                {
                    document.write("Error de Conexion");
                }
            }
            function grafica(venta,venta2,dia)
            {
                var line1 = new RGraph.Line('line1', venta,venta2);
                line1.Set('chart.background.grid', true);
                line1.Set('chart.linewidth', 5);
                line1.Set('chart.gutter.left', 35);
                line1.Set('chart.hmargin', 5);
                line1.Set('chart.tickmarks', 'circle');
                line1.Set('chart.units.post', '$');
                line1.Set('chart.colors', ['red', 'green']);
                //line1.Set('chart.curvy', 1);
                line1.Set('chart.curvy.factor', 0.25);
                line1.Set('chart.labels',dia);
                line1.Set('chart.background.grid.hlines', false);
                line1.Set('chart.background.grid.autofit.numvlines', 11);
                line1.Draw();
            }
            function primero()
           {
               callTheJsonp();
               callTheJsonp2();
               alert(v);
               alert(v2);
               alert(dia);
               grafica(v,v2,dia);
               
           }
</script> 
desde mi body llamo a la funcion primero <body onload="primero()">

puse alert para verificar su contenido de dichas variables y no contienen nada.

Alguna idea, alguien que vea mi error