Refactor queue AJAX function.