Please find the mistake

Handle problems or report system bug
Post Reply
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Please find the mistake

Post 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
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: Please find the mistake

Post 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
 }
...
😴
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Please find the mistake

Post 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 ?
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: Please find the mistake

Post 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>
😴
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Please find the mistake

Post 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
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Please find the mistake

Post 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>
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: Please find the mistake

Post by shrmaprem0202 »

francisco wrote: Thu Jan 18, 2024 10:51 am
shrmaprem0202 wrote: Thu Jan 18, 2024 7:55 am Thankyou now all problems solved i used index for users list count thanks for giving time love you ❤️❤️❤️
Hariph
Posts: 45
Joined: Tue May 23, 2023 9:33 pm

Re: Please find the mistake

Post by Hariph »

How to display username, for example a code that says "welcome back (username)"
samuel_anttunes
Posts: 29
Joined: Thu Mar 09, 2023 12:25 pm

Re: Please find the mistake

Post by samuel_anttunes »

Create a user lister

Enter codes

Code: Select all

 welcome back %username% 
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:

Code: Select all

<div id="nameDiv"></div>


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.
Post Reply