Added detailed error handling for ajax requests