Update to work with ajax requests

Simple update to make better errors work with ajax requests. Doesn't require too much extra code.