<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
<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:
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 "—":
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
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 "—":
<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>