I am writing a generic function that will be reused in several places in my script.
The function uses ajax (using the jQuery library), so I want to somehow pass a function (or line of code) to this function to execute when ajax is complete. I believe this should be a callback function, but after reading a few callback answers, I'm still a little confused about how I will implement in my case.
My current function:
function getNewENumber(parentENumber){
$.ajax({
type: "POST",
url: "get_new_e_number.php",
data: {project_number: projectNumber, parent_number: parentENumber},
success: function(returnValue){
console.log(returnValue);
return returnValue;
},
error: function(request,error) {
alert('An error occurred attempting to get new e-number');
}
});
}
With this function, I want to be able to do something in the same way as other jQuery functions, i.e.
var parentENumber = E1-3;
getNewENumber(parentENumber, function(){
alert(
});
source
share