Make loading cancellable; emit the correct events when readyState changes.