Preload and error handling for ajax request