Good, I have a variable nombre
within document.ready
that I want to access from outside document.ready
but I can not. If I declare the variable outside the document.ready
, when I assign a value within the document.ready
, it is lost when I exit.
I have read that if you declare the variable from outside the function, it becomes global and can be accessed from the whole document but something I am doing wrong.
I put the name variable as an example.
$(document).ready(function(){
url = new URL(location.href); //Mediante esta propiedad accedemos a la dirección URL completa de la página mostrada en una ventana
datos = JSON.parse(url.searchParams.get('objJson')); //Hacemos el proeso inverso, convertimos el string enviado a objeto Json
//La propiedad searchParams de la interfaz URL devuelve un objeto URLSearchParams que permite el acceso a los argumentos de consulta GET contenidos en la URL.
for(var i = 0; i < datos.length; i++){
//alert(datos[i].api_key);
}
nombre="adios";
});
alert(nombre);