I am making a function that posts AJAX requests.
I need to call it from multiple pages, how can I make a callback method inside the done method? Or even a second callback for beforesend events.
function post_ajax(URL,CONTENT_TYPE,$RENDERING_DIV,PARAMS={},callback_function){
$.post(URL, PARAMS, null, CONTENT_TYPE)
.done(data => {
callback_function()
}).fail(() => alert('an error occurred'));
}
//function call
$('#mybtn').click(()=>{
post_ajax('a_script.php','html','#div_res',{},callback_function())
})
return $.ajaxthen let your calling function handle the promise.datawithin.donebefore passing it to the callback function. Providing the use-case / reason helps provide a sensible answer otherwise it looks like an XY Problem (re-inventing an existing wheel)