Skip to content

Instantly share code, notes, and snippets.

@eblaauw
Last active August 29, 2015 14:17
Show Gist options
  • Save eblaauw/0b364102cc5c6f6cb708 to your computer and use it in GitHub Desktop.
Save eblaauw/0b364102cc5c6f6cb708 to your computer and use it in GitHub Desktop.
Toetsweek
//
// JAVASCRIPT OBJECTS
//
//Versie 1
var auto1 = {
merk: "Nissan",
model: "GT-R",
bouwjaar: 2012,
vermogen: ["545hp", "550hp"]
};
//Versie 2
var auto2 = new Object();
auto2.merk = "Nissan";
auto2.model= "GT-R";
auto2.bouwjaar = 2012;
auto2.vermogen = ["545hp", "550hp"] ;
//Versie 3
var auto3 = new Object();
auto3["merk"] = "Nissan";
auto3["model"]= "GT-R";
auto3["bouwjaar"] = 2012;
auto3["vermogen"] = ["545hp", "550hp"];
//simpele versie
{
"firstName": "John" ,
"lastName": "Doe"
}
//versie met array
{
"employees": [
{
"firstName": "John" ,
"lastName": "Doe"
}, {
"firstName": "Anna" ,
"lastName": "Smith"
}, {
"firstName": "Peter" ,
"lastName": "Jones"
}
] }
function Auto2(merk, model, jaar,
vermogen){
this.merk = merk;
this.model = model;
this.bouwjaar= jaar;
this.vermogen = vermogen;
this.AutoGegevens = AutoGegevens;
this.addVermogen = addVermogen;
function addVermogen(verm){
this.vermogen.push(verm);
}
function AutoGegevens() {
var elem = document.getElementsByTagName('body');
var body = elem[0];
var p = document.createElement('p');
p.innerHTML = 'test' + this.merk;
body.appendChild(p)
}
}
var verm =["70hp"];
var auto5 =
new Auto2("Nissan", "Leaf", 2013, verm);
auto5.addVermogen("75hp");
console.log(auto5);
window.onload = function() {
auto5.AutoGegevens();
};
obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " Last name: " + obj.employees[1].lastName;
if (window.XMLHttpRequest) {
// nieuwe xmlhttprequest
var xhttp = new XMLHttpRequest();
}
else { // Internet Explorer 5 en 6
var xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
// Bij asynchroon controleer of data binnen is
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var xmlDoc = xhttp.responseXML;
// Hier komt je code om data te manipuleren;
//functie aanroepen om data naar pagin te schrijven
addData(xmlDoc);
} };
//asynchroon ophalen van xml bestand met GET
xhttp.open("GET", "xml/notes.xml", true);
//Aanvraag versturen naar server
xhttp.send("");
/**
* Verwerk xml data en toont het op scherm
* @param data xmldoc
*/
function addData(data){
//Body element ophalen
var allBody = document.getElementsByTagName('body');
var body = allBody[0];
//alle notities opslaan in variabele
var note = data.getElementsByTagName('note');
for(var i = 0; i < note.length; i++){
//p element aanmaken voor het toevoegen van p tags in de body.
var p = document.createElement('p');
p.innerHTML = note[i].getElementsByTagName("body")[0].childNodes[0].nodeValue;
body.appendChild(p);
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment