Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!