-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp1.3.js
75 lines (60 loc) · 3.62 KB
/
mp1.3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function goToProfile(x){
sessionStorage.setItem('userId', x);
window.location.assign("user.html");
}
$("MP1.3.html").ready(function(){
var root = 'https://jsonplaceholder.typicode.com';
var j=10
var z = 0;
var arr;
$.ajax({
// url: root + '/photos?id=' + inputid,
url: root + '/posts',
type: "GET",
dataType: "json",
success: function(data) {
data.reverse();
$.each(data, function(i) {
if(i<j)
$.ajax({
url: root + "/users",
type: "GET",
dataType: "json",
success: function (dat){
for(var x = 0; x < dat.length; x++){
if(dat[x].id === data[i].userId){
$("#main").append('<div class="article"><div class="title">'+data[i].title+'</d iv><div class="name" onclick="goToProfile(' + dat[x].id + ')">By @'+dat[x].username+'</div><div class="text">'+data[i].body+'</div><div class="space"></div></div>');
z++;
break;
}
}
}
})
});
$("#more").click(function(){
$("#main").empty();
$("#main").append("<h2>Newsfeed</h2>")
j+=10;
$.each(data, function(i) {
i = i + z;
if(i<j)
$.ajax({
url: root + "/users",
type: "GET",
dataType: "json",
success: function (dat){
for(var x = 0; x < dat.length; x++){
if(dat[x].id === data[i].userId){
$("#main").append('<div class="article"><div class="title">'+data[i].title+'</div><div class="name" onclick="goToProfile(' + dat[x].id + ')"> By @'+dat[x].username+'</div><div class="text">'+data[i].body+'</div><div class="space"></div></div>');
z++;
break;
}
}
}
})
});
});
}
});
//$("#newsfeed_inner").append('"<div class="article"><div class="name">'+tempname+'</div><div class="title">lol</div><div class="text">lol</div><div class="clr"></div></div>"');
});