Reputation: 1575
I have ajax call function which have parameter function and it's looks like this
function selectedLang(func) {
let selected = selectLang.options[selectLang.selectedIndex].value;
$.ajax({
url: 'lang.php',
type: "POST",
dataType: 'json',
data: { language: selected },
success: function (data) {
// call here displayData function with parameter
func(data);
}
});
}
inside success
i want to call function displayData
with parameter data
function displayData(data) {
// some data
}
selectedLang(displayData);
Right now i'm getting an error that func
is not a function
Upvotes: 0
Views: 64
Reputation: 517
It looks like it is working. https://jsfiddle.net/bpomehv5/
Check out this fiddle
function selectedLang(func) {
$.ajax({
url: 'https://randomuser.me/api',
type: "GET",
dataType: 'json',
success: function (data) {
// call here displayData function with parameter
func(data);
}
});
}
function showIt (data) {
console.log(data);
}
selectedLang(showIt);
Upvotes: 1