// Mini-lab 11: AJAX + JSON
// INFO 343 Autumn 2012
// Morgan Doocy
// When the document's ready, attach a click handler to the 'fetch' button.
$(document).ready(function() {
$('#fetch').click(fetchClick);
});
// Handle clicking on the 'fetch' button. (Make Ajax request.)
function fetchClick() {
// Make AJAX request for images.json here!
}
// Provided Ajax error handler function (displays useful debugging information).
function ajaxError(jqxhr, type, error) {
var msg = "An Ajax error occurred!\n\n";
if (type == 'error') {
if (jqxhr.readyState == 0) {
// Request was never made - security block?
msg += "Looks like the browser security-blocked the request.";
} else {
// Probably an HTTP error.
msg += 'Error code: ' + jqxhr.status + "\n" +
'Error text: ' + error + "\n" +
'Full content of response: \n\n' + jqxhr.responseText;
}
} else {
msg += 'Error type: ' + type;
if (error != "") {
msg += "\nError text: " + error;
}
}
alert(msg);
}