Skip to content
Permalink
591e807457
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
49 lines (41 sloc) 1.36 KB
var base = "http://phonebk.develop.digitalmediauconn.org/phonebook.php";
function getAllPeople(callback) {
var ajaxcall = new XMLHttpRequest();
ajaxcall.onreadystatechange = function() {
if (ajaxcall.readyState == 4 && ajaxcall.status == 200) {
callback(ajaxcall.responseText);
}
};
ajaxcall.open("GET", base + "?do=getAllPeople", true);
ajaxcall.send();
}
function createElement(elemName, classes, text, id, href) {
var elem = document.createElement(elemName);
for (var i = 0; i < classes.length; i++) {
elem.classList.add(classes[i])
}
elem.appendChild(document.createTextNode(text));
elem.setAttribute("id", id);
elem.setAttribute("href", href)
return elem;
}
function format(text) {
var arr = JSON.parse(text);
arr.sort(function(a,b) {
return a.lastname > b.lastname;
});
var parent = document.querySelector("body");
console.log(arr);
for (var i = 0; i < arr.length; i++) {
var person = arr[i];
var div = createElement("div", ["person"], "");
var name = createElement("h3", [], person.firstname + " " + person.lastname);
var phone = createElement("a", ["phone-number"], person.phone,"", "/" + person.lastname); //add URL HERE
var email = createElement("a", ["email"], person.email, "", "mailto:"+ person.email);
div.appendChild(name);
div.appendChild(phone);
div.appendChild(email);
parent.appendChild(div);
}
}
getAllPeople(format);