Added error detection and timeout to API ajax call