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

77
Vistas
Make a asynchronous permission function that can be used multiple times?

I'm trying to make a function that return true or false given a specific permission class.

I want to use this function across multiple functions.

This is what I have so far but it does not quite work since the asynchronous nature of the ajax call:

const hasPermission = (permissionClass) => {

  $.ajax({
    url: "/home/getUserPermissions",
    method: "POST",
    contentType: "application/json",
    data: JSON.stringify({ data: permissionClass }),
    success: function (response) {
      return true;
    },
    error: function (err) {
      return false;
    }
  }); 

}

const buildView = () => {

  if(hasPermission("1")) {
    // Buld permission view
  } 
}

Any help is appreciated!

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