request: error handling and data from onLoad

The onLoad handler may have already parsed the data and did some transformations.
We don't need to parse it again hence the check if typeof data == 'object'.

Added an event "onError" called when the server returns an error