Add function to handle AJAX result