3. Introduce Javascript Template
var html = "<h1>"+data.title+"</h1>"
html += "<ul>"
for(var i=0; i<data.supplies.length; i++) {
html += "<li><a href='supplies/"+data.supplies[i]+"'>"
html += data.supplies[i]+"</a></li>"
}
html += "</ul>"
Website:http://designveloper.com
Address:250/6BauCat,Ward11,
TanBinhDistrict,HCMCity
4. JSON
• JSON: JavaScript Object Notation.
• JSON is syntax for storing and exchanging text information.
Much like XML.
• JSON is smaller than XML, and faster and easier to parse.
• http://www.json.org/
• http://www.w3schools.com/json/
http://caniuse.com/json
Website:http://designveloper.com
Address:250/6BauCat,Ward11,
TanBinhDistrict,HCMCity
5. JSON and Javascript Object
Javascript Object
Var ob={firstname:”david”}
Var ob={'firstname':”david”}
Var ob={'firstname':”david”
, full_name =function(){
alert(this.firstname);}
}
Any javascript structure
JSON.stringify()
JSON
{“first_name”:”david”}
Value one of six data types
Strings, number, object,
array,boolean, or null
JSON.parse()
Website:http://designveloper.com
Address:250/6BauCat,Ward11,
TanBinhDistrict,HCMCity
7. Working with javascript object
• Debug javascript object with your browser
• Modify array object in javascript
• Loop through object in javascript
• Access object in array
Website:http://designveloper.com
Address:250/6BauCat,Ward11,
TanBinhDistrict,HCMCity
8. Parse JSON
• Using Ajax
• Using Jquery
Website:http://designveloper.com
Address:250/6BauCat,Ward11,
TanBinhDistrict,HCMCity