Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/06/2012, 01:49
riahc3
 
Fecha de Ingreso: abril-2012
Mensajes: 39
Antigüedad: 12 años
Puntos: 0
Respuesta: Acceder una variable fuera de una funcion?

Cita:
Iniciado por America|UNK Ver Mensaje
-----------------------
requestValue: function(key, callback){
var request = {
key: key, .....................

this._sendRequest(data);


var unavariable="";
var remoteStorage = new CrossDomainStorage("http://algo.com", "/server.html");
unavariable=remoteStorage.requestValue("unallave", function(key, value){
alert("El valor para '" + key + "' es '" + value + "'");
return value;
});

alert ("probamos " + unavariable);

-----------------------

Fijate que el callback de requestValue está llamando a this._sendRequest(data);
Donde data esta nuestro callback, pero mira la funcion _sendRequest nuestro callback no esta llamandose por ninguna parte.

En pocas palabras tu callback no está realizando ninguna acción por eso no asigna la variable.
Vale entonces que tengo que hacer para que lo haga?

Tengo esto

Código:
remoteStorage.requestValue("something", function(key, value){
					
				
		
					valor=value;
					remoteStorage.v=value;
					
			
					
						hero<?php echo $_SESSION['countforfor']; ?> =  value;
						document.getElementById("fotop<?php echo $_SESSION['countforfor']; ?>").src=hero<?php echo $_SESSION['countforfor']; ?>;
						document.getElementById("fotog<?php echo $_SESSION['countforfor']; ?>").src=hero<?php echo $_SESSION['countforfor']; ?>;
						alert("value " + value);
					
					
					});
Que solo me funciona si pongo el alert. Sin el alert, value se queda con el mismo valor todo el rato.