Howdy, Campers
I am in the midst of trying to figure out exactly how the clickController.client.js page works and how it works in conjunction with the HTML page on one side and the ajax-funcitons.js file on the other.
Specifically, what is this line doing? How is it associated with a user’s action on the HTML page?
ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, updateClickCount));
Here is the entirety of the code from the clickController.client.js page:
'use strict';
(function () {
var addButton = document.querySelector('.btn-add');
var deleteButton = document.querySelector('.btn-delete');
var clickNbr = document.querySelector('#click-nbr');
var apiUrl = appUrl + '/api/:id/clicks';
function updateClickCount (data) {
var clicksObject = JSON.parse(data);
clickNbr.innerHTML = clicksObject.clicks;
}
ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, updateClickCount));
addButton.addEventListener('click', function () {
ajaxFunctions.ajaxRequest('POST', apiUrl, function () {
ajaxFunctions.ajaxRequest('GET', apiUrl, updateClickCount);
});
}, false);
deleteButton.addEventListener('click', function () {
ajaxFunctions.ajaxRequest('DELETE', apiUrl, function () {
ajaxFunctions.ajaxRequest('GET', apiUrl, updateClickCount);
});
}, false);
})();