First of you are not actually returning anything in the function. You are returning something inside a sub function. Secondly your call will be async and not return anything at once.
An easy fix is this https://stackoverflow.com/a/5316755/1305117
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Originally i had this function:
$.ajax({
url: "/albums/getAlbumData",
data: {
albumID: albumID,
dataType: dataType
}
})
.done(function(data){
$("#infoModalData").text(data));
});
within a block that was triggered when pressing a button. We are adding more buttons so it makes sense to push the ajax call to a function:
function getAlbumData(albumID, dataType) {
$.ajax({
url: "/albums/getAlbumData",
data: {
albumID: albumID,
dataType: dataType
}
})
.done(function(data){
console.log(data);
return(data);
});
};
The console.log() shows the correct data but it doesn't return anything to update the DOM. What i'm doing incorrectly.
First of you are not actually returning anything in the function. You are returning something inside a sub function. Secondly your call will be async and not return anything at once.
An easy fix is this https://stackoverflow.com/a/5316755/1305117
Please or to participate in this conversation.