Page 1 of 1
Please find the mistake
Posted: Wed Jan 17, 2024 7:47 pm
by shrmaprem0202
Code: Select all
<p id="demo">h</p>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var obj=this.responseText;
var obja = JSON.parse(obj);
a0 = i need to use ID OR USERNAME << VAR << VAR logindate with date sort;
document.getElementById("demo").innerHTML = a0;
}
};
xhttp.open("GET", "https://waptrick360.wapka.site/testjson.json", true);
xhttp.send();
</script>
I need to use lastlogin tag in for(var i=0;i<len;i++) js code so i can use user data table with help of api and fitter by last login and most login and multiple options
Re: Please find the mistake
Posted: Thu Jan 18, 2024 12:11 am
by francisco
Hello! To sort users by login date, you can implement the following approach:
Code: Select all
<p id="demo"></p>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var obj = this.responseText;
var obja = JSON.parse(obj);
var sortedResults = obja.result.sort(function (a, b) {
return new Date(b.var.logindate) - new Date(a.var.logindate);
});
var table = '<table><tr><th>Username</th><th>Logindate</th></tr>';
sortedResults.forEach(function (result) {
table += '<tr><td>' + result.username + '</td><td>' + result.var.logindate + '</td></tr>';
});
table += '</table>';
document.getElementById("demo").innerHTML = table;
}
};
xhttp.open("GET", "https://waptrick360.wapka.site/testjson.json", true);
xhttp.send();
</script>
Please note that your example JSON has a syntax error where it has a comma in the last item of "var", you must remove this comma to make the JSON valid and allow the javascript code to execute:
Code: Select all
...
"totallogin": "21", <--- remove this comma wherever it appears
}
...
Re: Please find the mistake
Posted: Thu Jan 18, 2024 7:55 am
by shrmaprem0202
francisco wrote: ↑Thu Jan 18, 2024 12:11 am
Now it's working but there us a problem if logindate is not a valid date or empty what can we do ?
Re: Please find the mistake
Posted: Thu Jan 18, 2024 10:51 am
by francisco
shrmaprem0202 wrote: ↑Thu Jan 18, 2024 7:55 amNow it's working but there us a problem if logindate is not a valid date or empty what can we do ?
In this case we can first filter the results of those who have a valid logindate and display the invalid results at the end of the table, replacing the logindate with "—":
Code: Select all
<div id="demo"></div>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var obj = this.responseText;
var obja = JSON.parse(obj);
var validResults = obja.result.filter(function(result) {
return result.var.logindate && !isNaN(new Date(result.var.logindate));
});
var invalidResults = obja.result.filter(function(result) {
return !result.var.logindate || isNaN(new Date(result.var.logindate));
});
var sortedResults = validResults.sort(function(a, b) {
return new Date(b.var.logindate) - new Date(a.var.logindate);
});
var table = '<table><tr><th>Username</th><th>Logindate</th></tr>';
sortedResults.forEach(function(result) {
table += '<tr><td>' + result.username + '</td><td>' + result.var.logindate + '</td></tr>';
});
invalidResults.forEach(function(result) {
table += '<tr><td>' + result.username + '</td><td>—</td></tr>';
});
table += '</table>';
document.getElementById("demo").innerHTML = table;
}
};
xhttp.open("GET", "https://waptrick360.wapka.site/testjson.json", true);
xhttp.send();
</script>
Re: Please find the mistake
Posted: Thu Jan 18, 2024 6:51 pm
by shrmaprem0202
francisco wrote: ↑Thu Jan 18, 2024 10:51 am
shrmaprem0202 wrote: ↑Thu Jan 18, 2024 7:55 am Now all done thanks for your support
god bless you friend
please add a for loop in this code so if i want to show 5 users i can
Re: Please find the mistake
Posted: Fri Jan 19, 2024 4:08 am
by shrmaprem0202
francisco wrote: ↑Thu Jan 18, 2024 10:51 am
shrmaprem0202 wrote: ↑Thu Jan 18, 2024 7:55 amNow it's working but there us a problem if logindate is not a valid date or empty what can we do ?
In this case we can first filter the results of those who have a valid logindate and display the invalid results at the end of the table, replacing the logindate with "—":
Code: Select all
<div id="demo"></div>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var obj = this.responseText;
var obja = JSON.parse(obj);
var validResults = obja.result.filter(function(result) {
return result.var.logindate && !isNaN(new Date(result.var.logindate));
});
var invalidResults = obja.result.filter(function(result) {
return !result.var.logindate || isNaN(new Date(result.var.logindate));
});
var sortedResults = validResults.sort(function(a, b) {
return new Date(b.var.logindate) - new Date(a.var.logindate);
});
var table = '<table><tr><th>Username</th><th>Logindate</th></tr>';
sortedResults.forEach(function(result) {
table += '<tr><td>' + result.username + '</td><td>' + result.var.logindate + '</td></tr>';
});
invalidResults.forEach(function(result) {
table += '<tr><td>' + result.username + '</td><td>—</td></tr>';
});
table += '</table>';
document.getElementById("demo").innerHTML = table;
}
};
xhttp.open("GET", "https://waptrick360.wapka.site/testjson.json", true);
xhttp.send();
</script>
Profile photo problem
Code: Select all
<p id="demo"></p>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var obj = this.responseText;
var obja = JSON.parse(obj);
var sortedResults = obja.result.sort(function (a, b) { return new Date(b.logindate) - new Date(a.logindate);
});
var table = '';
sortedResults.forEach(
function (result){
table +='<div class="menu"><table cellpadding="0" cellspacing="0" width="100%"><tr valign="top"><td width="50"><img src="'+result.var.avatar+' " alt="" class="Avatar" style=""><td><a href="/user/?id='+result.id+'" class="">'+result.username+' </a><br/>'+result.logindate+'</td></td></tr></table></div>';
});
document.getElementById("demo").innerHTML = table;
}
};
xhttp.open("GET", "https://api.wapka.org/35042:9vcukscu0vo1acqpg964ji8n87/userinfo?limit=999999", true);
xhttp.send();
</script>
Re: Please find the mistake
Posted: Sat Jan 20, 2024 2:38 pm
by shrmaprem0202
Re: Please find the mistake
Posted: Wed Feb 07, 2024 10:39 am
by Hariph
How to display username, for example a code that says "welcome back (username)"
Re: Please find the mistake
Posted: Fri Feb 09, 2024 4:38 am
by samuel_anttunes
Create a user lister
Enter codes
Enter Config~
Code: Select all
<id> #%VAR(USER_ID)%# </id>
<limit>1</limit>
This is the simple way to do it. But you can use javascript to improve this.
---------------------------------
Example in JavaScript
Enter codes
Code: Select all
<script>function name() {
//Get the username.
var pname = "Welcome back %username%!";
// div name for id.
var div = document.getElementById("nameDiv");
// Set the content of the div to the phrase you got.
div.innerHTML = pname;
}
//Call this function to display the phrase when necessary.
name(); </script>
Enter Config~
Code: Select all
<id> #%VAR(USER_ID)%# </id>
<limit>1</limit>
to display the welcome user, use the div code:
Attention, always use the div on top of the user list created with javascript.
I advise you to create the user list in the footer of the site if you are going to use this version with javascript.