There is this one small table where we want metadata to be pulled from an API and displayed. There is already a post about (passing configurable variable to JavaScript). The only thing that’s different is the Ajax portion where the custom error messages are populated:

...

$.ajax({
  type: "GET",
  url: settings.api_url,
  success: function (response) {
    if (!$.isEmptyObject(response)) {
      if (response.fileSize) {
        $('span#myFileSize').html(response.fileSize);
      }
      if (response.fileDate) {
        $('span#myFileDate').html(response.fileDate);
      }
    }
  },
  error: function () {
    $('span#myFileSize').html(settings.file_size_error);
    $('span#myFileDate').html(settings.file_date_error);
  }
});

...

The error event is fired if the API call fails for any reason other than cross-domain requests.

Resources