H. Eberhardt H. Eberhardt - 1 month ago 11
Javascript Question

Get AJAX return, concat and build an table

i'm not able to assign my AJAX return as variable to concat.

Here is the code:

function GetSex() {
$.ajax({
url: '/SEX/GetAllSex/',
success: function (data) {
console.log(data);
}
});
}

function GetUsers() {
var Pistas = null;
$.ajax({
url: '/Users/GetAllUsers/',
success: function (data) {
console.log(data)

}
});
}


I want to concat the results, so that's what i'm doing:

var Sex = GetSex();
var Users = GetUsers();

var x = Users.concat(Sex);


It says that Sex and Users variable is undefined!

I don't understand.

Thanks in advance =)

Answer

Well,

I just didn't declare the variables before:

Final code was like:

var Sex;
var Users;

function GetSex() {
        $.ajax({
            url: '/SEX/GetAllSex/',
            success: function (data) {
                Sex = data;
                console.log(data);
            }
        });
     }

     function GetUsers() {
         var Pistas = null;
         $.ajax({
             url: '/Users/GetAllUsers/',
             success: function (data) {
                 Users = data;
                 console.log(data)

             }
         });
     }

Thank you anyway.