Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
JS class variable not setting

I have created an AJAX promise and when it is complete I am trying to set a class variable but it is not setting for some reason. I thought this was an ASYNC issue but the promise should have resolved that issue. It's possible it is a scope issue but I don't know how to resolve it.

$(document).ready(function(){

class Tables {

    constructor() {
       Tables.Action   = this.GetAction()
       Tables.Headers  = ''

      this.InitHeaders()

      console.log(Tables.Headers)
    //this.InitDatables()


    }
    GetAction() {
      var Segments  = window.location.pathname.split("/")
      var URL       = '/'+Segments[1]

        return URL
    }

    InitHeaders(){

        this.GetHeaders().then(function(data) {
            // Run this when your request was successful
            Tables.Headers = data
          }).catch(function(err) {
            // Run this when promise was rejected via reject()
            console.log(err)
          })
    }
    GetHeaders()
    {
       return new Promise(function(resolve, reject) {
            $.ajax({

              url     : Tables.Action +'/GetHeaders',
              success: function(data) {
                    resolve(data) // Resolve promise and go to then()
              },
              error: function(err) {
                reject(err) // Reject the promise and go to catch()
              }
            })
          });

    }

  }

let Table = new Tables();


});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda