Update functions.js

Added error handling to the XMLHttpRequest.