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

250
Vistas
Accessing jquery data variable in ajax call in server side script

I have a few ajax calls in my app they all go to the same file server side. i want to know if I can use a variable... I want to have a way to distinguish the call from other calls and of course, use the variable to select which script in the file to send back to the client. I do not need to use the variable after the script has run in any way. Or am i going about this the wrong way?

for example this is one of my ajax calls

var variable1 = 'currentuser1var';

return $.ajax({
          type: 'GET',
          url: '/users/index', 
          data: {currentuser1var: variable1},
          dataType: 'script',
        });

then the script in my server side file would be

if (currentuser1var) { script here }

else if (currentuser2var) { script here }

...

I am not sure how to access the string, inside the object call. Do i need to access the object first then the string? Or just reference the variable some how.

EDIT Tried

if(typeof(currentuser1var) != "undefined") { script here }

to no avail.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If you were using PHP, your server side script would be:

if(isset($_GET['currentuser1var'])) {


    ... script to process the currentuser1var variable ...


} else if (isset($_GET['currentuser2var'])) {


    ... script to process the currentuser2var variable ...


}
about 4 years ago · Santiago Trujillo Denunciar

0

Aj was right here I guess for php as I did not list what server side code I was using, but simply put, I changed my ajax call to

return $.ajax({
  type: 'GET',
  url: '/users/show', 
  data: { currentuser1var: 'variable1'},
});

where the key is currentuser1var and the value variable1 is a string and leave out defining the variable else where in the code. That way the url comes through correctly to the server being /users/show?currentuser1var=variable1. And in my destination file add my ruby code there to use the variables.

about 4 years ago · Santiago Trujillo Denunciar
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