I have this module that consists of AJAX functionality I'm looking to export to my Client Controller, but I'm getting Module is not defined, I'm using NodeJS and the Cloud9 Environment.
AJAX Module
module.exports = {
appUrl: window.location.origin,
ready: function(fn) {
if(typeof fn !== 'function') {
return;
}
if(document.readyState === 'complete') {
return fn();
}
document.addEventListener('DOMContentLoaded', fn, false);
},
ajaxRequest: function(method, url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState === 4 && xmlhttp.status === 200) {
callback(xmlhttp.response);
}
};
xmlhttp.open(method, url, true);
xmlhttp.send();
}
};
Client Controller
'use strict';
var ajaxFunctions = require("../common/ajax-functions.js");
(function(){
var profileId = document.querySelector('#profile-id') || null;
var profileUsername = document.querySelector('#profile-username') || null;
var profileRepos = document.querySelector('#profile-repos') || null;
var displayName = document.querySelector('#display-name');
var apiUrl = ajaxFunctions.appUrl + '/api/:id';
function updateHtmlElement(data, element, userProperty) {
element.innerHTML = data[userProperty];
}
ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, function(data){
var userObject = JSON.parse(data);
updateHtmlElement(userObject, displayName, 'displayName');
if(profileId !== null) {
updateHtmlElement(userObject, profileId, 'id');
}
if(profileUsername !== null) {
updateHtmlElement(userObject, profileUsername, 'username');
}
if(profileRepos !== null) {
updateHtmlElement(userObject, profileRepos, 'publicRepos');
}
}));
})();
var ajaxFunctions = require("../common/ajax-functions.js");points to the correct location, and thatajax-functions.jsexports a valid module.ajax-functions.js:)