¿Alguien podría ayudarme a actualizar una variable global (user_ID) con la respuesta de una solicitud de AJAX?
Intenté lo siguiente sin éxito: https://newbedev.com/jquery-storing-ajax-response-into-global-variable . Alert() ha declarado consistentemente que la var global no estaba definida,
Tenga en cuenta que el mensaje console.log() indica un ID de usuario válido en el ámbito interno. solo necesito sacarlo..
Gracias :-)
// update global variable (user_ID) with ajax response var user_ID; // empty var to be populated with result function receiveUserId(layerURL) { $.ajax({ url: layerURL, crossDomain: true, type:"GET", // process the response from the server success: function(result){ user_ID = result.user_ID; //JSON obj.prop console.log("The server responded with the following user ID: ", user_ID) return user_ID } }); }