To close.
$(document).ready(function() { function ajax_start() { alert("starting..."); } $.ajax({ beforeSend: ajax_start,
You need to do this because
ajax_start() evaluates the value returned by a function called ajax_start , butajax_start evaluates the function itself .
Edit Repeat: OP Comment
"how to include the second function in the callback. Something like: beforesend: ajax_start, other_function (isnβt it?)?
There are several ways to do this. Combine them using an anonymous function:
$.ajax({ // if you need the arguments passed to the callback beforeSend: function (xhr, settings) { ajax_start(); other_function(); }, url: "insert_part.php", type:"POST", data: "customer="+customer });
Or simply declare a named function that does what you want, and then use it:
function combined_function(xhr, settings) { ajax_start(); other_function(); } $.ajax({ beforeSend: combined_function, url: "insert_part.php", type:"POST", data: "customer="+customer });
source share