The specific error that you get relates to this line:
var vaxData = document.getElementById(data);
As there is no data variable in scope here.
You may be thinking that returning a value from the done callback would populate this variable, but it won't because it's in a different scope (which you could fix by declaring var data before the $.ajax call) and it happens at a different time and context. The execution of the javascript won't wait for the done callback to finish and var vaxData = document.getElementById(data); will run before alert("Retrieved " + data.length + " records from the dataset!"); will run. A better explanation for this sort of thing can be found on MDN.
Also, document.getElementById() expects a string not an array like the data returned from the API should be.
To resolve this issue you could declare the data variable before the call to $.ajax and execute the update of the table in the done callback function. In the example below, I've used the a function called update_table to do this and I've called data vaccination_data.
One other issue is the HTML for the table is not completed in your example.
var vaccination_data = [];
$.ajax({
url: "https://health.data.ny.gov/resource/nvtm-yit2.json",
type: "GET",
data: {
"$limit" : 5000,
"$$app_token" : 'your_app_token'
}
}).done(function(api_data) {
vaccination_data = api_data;
update_table();
});
var vaxData = document.getElementById('vaxData');
const cell_keys = ['city', 'county', 'percentcompletelyimmunized'];
function create_element(tag, attributes, children = []) {
const element = Object.assign(document.createElement(tag), attributes);
element.append(...children);
return element;
}
function create_row_element(item) {
return create_element(
'tr', {},
cell_keys.map( (key) => create_element('td', { innerHTML: item[key] }) )
);
}
function update_table() {
vaxData.innerHTML = '';
vaxData.append(...vaccination_data.map(create_row_element));
}
<table>
<thead>
<tr>
<th>City</th>
<th>County</th>
<th>Percent Immunized</th>
</tr>
</thead>
<tbody id="vaxData"></tbody>
</table>
Edit to add, this line: vaccination_data = api_data; also uses something called a closure to work so that the done callback function has a reference to the vaccination_data variable.