forked from node-girls/node-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
619bd5e
commit 30c2158
Showing
7 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Node Girls CMS tutorial</title> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
$(document).ready(function() { | ||
$.ajax({ | ||
url: '/posts', | ||
dataType: 'json', | ||
success: function(data) { | ||
|
||
document.onreadystatechange = function () { | ||
if (document.readyState === 'complete') { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function() { | ||
if(xhr.readyState === 4){ | ||
if (xhr.status === 200){ | ||
var data = JSON.parse(xhr.responseText); | ||
for (var blogPost in data) { | ||
var postDiv = document.createElement('div'); | ||
var postText = document.createElement('p'); | ||
var thumbnail = document.createElement('img'); | ||
var postContainer = document.getElementsByClassName('post-container')[0]; | ||
|
||
thumbnail.src = "./img/logo2.png"; | ||
thumbnail.className = "thumbnail"; | ||
postText.innerHTML = data[blogPost]; | ||
postDiv.className = "post"; | ||
|
||
postDiv.appendChild(thumbnail); | ||
postDiv.appendChild(postText); | ||
postContainer.appendChild(postDiv); | ||
|
||
var postDiv = document.createElement('div'); | ||
var postText = document.createElement('p'); | ||
var thumbnail = document.createElement('img'); | ||
var postContainer = document.getElementsByClassName('post-container')[0]; | ||
|
||
thumbnail.src = "./img/logo2.png"; | ||
thumbnail.className = "thumbnail"; | ||
postText.innerHTML = data[blogPost]; | ||
postDiv.className = "post"; | ||
|
||
postDiv.appendChild(thumbnail); | ||
postDiv.appendChild(postText); | ||
postContainer.appendChild(postDiv); | ||
} | ||
}, | ||
error: function(error){ | ||
console.log(error); | ||
} | ||
else { | ||
console.error(xhr.responseText); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
xhr.open('GET', '/posts', true); | ||
xhr.send(); | ||
} | ||
} |
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
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
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
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