xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "https://api.parse.com/1/classes/Blog", true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('X-Parse-Application-Id', 'GKid48BAvytRnKn8Y8CFKiKQ8jIJSYwpUsr1vID1');
xmlhttp.setRequestHeader('X-Parse-REST-API-Key', '6bnW8hVQNvuLQYiDiXvMHwIvV0inEne93gLzOC0A');
xmlhttp.onload = function () {
if (xmlhttp.status === 200) {
var userInfo = JSON.parse(this.responseText);
console.log(this.responseText);
var arr = userInfo.results.reverse();
var text = "";
for (var i = 0; i < arr.length; i++) {
text += '<div class="blog-post"><div class="blog-header">'+arr[i].title + '</div><br><img width="560px;" src="' + arr[i].img + '"><br><div class="blog-text">' + arr[i].text + '</div><div class="blog-share"><a href="http://gamer-by-life.com/share/?title='+arr[i].title + '&text='+arr[i].text + '&img='+arr[i].img + '&time='+arr[i].createdAt + '"><img src="share.png"></a></div><br></div><br>';
}
document.getElementById('blogs').innerHTML=text;
}
};
xmlhttp.send();
function sortDate(a,b){
var aDate = new Date(a.createdAt);
var bDate = new Date(b.createdAt);
if(aDate == bDate)
return 0;
if(aDate < bDate)
return -1;
if(aDate > bDate)
return 1;
};
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "https://api.parse.com/1/classes/Blog", true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('X-Parse-Application-Id', 'GKid48BAvytRnKn8Y8CFKiKQ8jIJSYwpUsr1vID1');
xmlhttp.setRequestHeader('X-Parse-REST-API-Key', '6bnW8hVQNvuLQYiDiXvMHwIvV0inEne93gLzOC0A');
xmlhttp.onload = function () {
if (xmlhttp.status === 200) {
var userInfo = JSON.parse(this.responseText);
console.log(this.responseText);
debugger;
userInfo.results = userInfo.results.sort( sortDate );
var arr = userInfo.results.reverse();
var text = "";
for (var i = 0; i < arr.length; i++) {
text += '<div class="blog-post"><div class="blog-header">'+arr[i].title + '</div><br><img width="560px;" src="' + arr[i].img + '"><br><div class="blog-text">' + arr[i].text + '</div><div class="blog-share"><a href="http://gamer-by-life.com/share/?title='+arr[i].title + '&text='+arr[i].text + '&img='+arr[i].img + '&time='+arr[i].createdAt + '"><img src="share.png"></a></div><br></div><br>\n';
}
console.log(text);
}
};
xmlhttp.send();