Accessing the jquery data variable in the ajax call of the server-side script

advertisements

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.


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 ...

}