0
I need to call a function in Javascript where one of its parameters is a function.
In this case, how do I pass parameters within the function call?
Ex: (Function to be called first:
function getWS(data, success) {
$.ajax({
type: 'GET',
url: 'MinhaUrl',
data: data,
async: false,
crossDomain: true,
dataType: 'json',
success: success,
error: error,
});
}
Function in case of success in the above call:
function preencheLista(data, lista)
{
$.each(data, function (i, item) {
lista.push({ "id": item.id, "nome": item.nome })
});
}
Calling for:
//Aqui que está minha dúvida. Como passar data e marcas para esta função)
var marcas = [];
getWS(data, preencheLista(data, marcas));
The biggest problem is you want to use synchronous ajax. You should only manipulate the list of brands from within the successful ajax callback.
– bfavaretto