Last active
August 29, 2015 14:17
-
-
Save eblaauw/0b364102cc5c6f6cb708 to your computer and use it in GitHub Desktop.
Toetsweek
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//simpele versie | |
{ | |
"firstName": "John" , | |
"lastName": "Doe" | |
} | |
//versie met array | |
{ | |
"employees": [ | |
{ | |
"firstName": "John" , | |
"lastName": "Doe" | |
}, { | |
"firstName": "Anna" , | |
"lastName": "Smith" | |
}, { | |
"firstName": "Peter" , | |
"lastName": "Jones" | |
} | |
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obj = JSON.parse(text); | |
document.getElementById("demo").innerHTML = | |
obj.employees[1].firstName + " Last name: " + obj.employees[1].lastName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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