1

I am trying to parse a text file in my js. I am able to do it but when i return the processed data i get undefined as return value.

function getGroups(){
    var groups;
    $.get("http://localhost:8085/cust_js/my.txt", function(data) {

            var groups = data.split(',');
        //alert(""+groups)

    });
return groups;

}

$(function() {
    alert(""+getGroups())
});

EDIT : Used ajax .

function getGroups() //gets the groups of the user
{
var groups;
$.ajax({
url: "http://localhost:8085/cust_js/my.txt",
type: 'get',
dataType: 'text',
async: false,
success: function(data) { groups = data.split(","); }
});
return groups;
}

$(function() {
    alert(""+getGroups())
});
Mizan
  • 450
  • 1
  • 5
  • 28

0 Answers0