0

I have this code where tabsActive var turns into Javascript object as image below shows:

var tabsActive;

$(document).ready(function () {
    $.get(Routing.generate('configuracionPestanas', {
        estado_solicitud: 1,
        tipo_tramite: 1
    }), {}, 'json').done(function (data, textStatus, jqXHR) {
        tabsActive = JSON.parse(data.estadosWz[0]);

        console.log(tabsActive);
    });

    var tipoTramiteSolObj = $("select#solicitudUsuario_tipoRegistro"),
        oficinaRegionalSolObj = $("input#solicitudUsuario_oficinaRegional"),
        tipoTramiteSolVal;

    oficinaRegionalSolObj.select2({
        ....    
    }).select2("enable", tabsActive.wzSolicitud[0]);
});

Now I need to access a that object outside $.get request but seems like it doesn't exists since I get error on the line where I'm trying to access object properties:

select2("enable", tabsActive.wzSolicitud[0])

Why? What is the right way to access the object outside the $.get request?

enter image description here

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • Put `oficinaRegionalSolObj.select2({ ... ` code into `.done()` callback after `console.log`. You should clearly understand that ajax requests are executed asynchronously. – Regent Dec 12 '14 at 06:59
  • *"Why?"* Because **A**jax is **asynchronous**. *"What is the right way to access the object outside the `$.get` request?"* Passing it to a function *from* the `$.get` request. – Felix Kling Dec 12 '14 at 07:00

0 Answers0