You can iterate over the list using a forEach easily.
var listid=["fund","trans","ins"];
listid.forEach(function(id) {
getData(id);
});
function getData(id) {
var xhr = $.ajax({
url: "/en",
method: 'get',
global: false,
async: false,
data: {
idvalue: id
},
success: function(value) {
return value;
}
}).always(function(data, textStatus, jqXHR) {
// deal with the data
})
}
If you are using newer version of Jquery then The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are removed as of jQuery 3.0.
You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
function getData(id) {
var xhr = $.ajax({
url: "/en",
method: 'get',
global: false,
async: false,
data: {
idvalue: id
},
success: function(value) {
return value;
}
})
.done(function(data, textStatus, jqXHR ) {
// do something with value
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
}