I have an Ajax call in jQuery that returns a string of comma separated words.
Now I need to create an indexed array with the content of this string so that every word from the string has a number in the array. Later I need to use specific values from this array, e.g. the 3rd, the 4th and the 5th.
I tried the following but this returns undefined
when creating the var in the end.
If I alert myArray in the success function than I still get a comma separated string so I guess I am maybe missing the indexing part ?
Can someone tell me what I am doing wrong here ?
myArray = [],
myVar = 'someText';
$.ajax({
type: "post",
url: "ajax.php",
cache: "false",
data: {
node: 'fetchStuff',
languageFrm: languageFrm
},
success: function(data){
myArray = data.split(',');
},
error: function(){
}
});
myVar += myArray[2] + ' - ' + myArray[3] + ' - ' + myArray[4];