ai up, look at this silly code. I want to pass either a string or an array and return the data. This code does work, but it sucks. What would you recommend as the best way to remove the duplication and optimizing it as much as possible? thanks :)
var getData = function (dataFile) {
var ajaxResponse = [],
loop,
i;
if(dataFile instanceof Array) {
loop = dataFile.length;
for(i = 0; i < loop; i++) {
$.ajax({
url: dataFile[i],
type: "post",
async: false,
dataType: "json",
success: function (data) {
ajaxResponse[i] = data;
}
});
}
}
else {
$.ajax({
url: dataFile,
type: "post",
async: false,
dataType: "json",
success: function (data) {
ajaxResponse = data;
}
});
}
return ajaxResponse;
}
thanks people, I'll have to think about this. I could pass all the params as arrays if i wanted but that would cause me problems elsewhere. Basicaly i need to get the return values in the same way they came in, i.e. a single value or an array. The data being asked for is completely different. I could change it, but ill have to investigate which way is going to be better in the long run.