Whats the best way to put together a simple webpage that contains a javascript code that calls an ajax function to retrieve some data and finally display that data in the simple webpage.
That file is in the same folder on your server as the web page you are calling the Ajax script from.
You can replace "ajax_info.txt" with any web-accessible file on your domain.You can also call external APIs etc, as long as they are configured to respond to cross-site requests.
If you are set on using XMLHttpRequest you can listen for an error event.
xhttp.addEventListener("error", transferFailed);
function transferFailed(e) {
console.log("An error occurred while transferring the file.");
console.error(e);
}
See:
However, assuming you don’t have to support legacy browsers, I would be tempted to use the fetch API instead.