Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:43:54+00:00 2026-05-31T08:43:54+00:00

I’m trying to get some data from a PHP file which only gives a

  • 0

I’m trying to get some data from a PHP file which only gives a number after executing:

<?php
    include '../assets/class/login/loginsys.php';
    $extension = new extension;     
    $count = $extension->userCount();
    echo $count;        
?>

So the $count variable will be just a number. And I’m trying to retrieve that number and put it in a js variable for further use ( I need it a few times, if it were only once I would have used $.get() and applied it to the container I need ):

var oXHR = new XMLHttpRequest();  
oXHR.open("GET", "admin/user-count.php", true);  
oXHR.onreadystatechange = function (oEvent) {  
    if (oXHR.readyState === 4) {  
        if (oXHR.status === 200) {  
            console.log(oXHR.responseText)  
        } else {  
        console.log("Error", oXHR.statusText);  
        }  
    }  
}; 
oXHR.send();

I have tried the method above with little success, but I also tried it like this:

var users = $.get('admin/user-count.php', function(data) {
    console.log('There are '+data+' users found');
    return data;
});

The same result, nothing. So what am I doing wrong or how should I do it right ?

EDIT I have made a little mistake that I fixed now, the first method works as well as the second one. but now I need to store the data I get with the first method into a variable so I can use it later on. How do I do that and also which of the two methods is better ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:43:55+00:00Added an answer on May 31, 2026 at 8:43 am

    I would use the second code if you already have jQuery included:

    $.get('admin/user-count.php', function(data)
    {
      // Don't use "var" here, otherwise the variable won't be global!
      myGlobalVar = parseInt(data, 10);
      // Also possible: window["myGlobalVar"] = parseInt(data, 10);
    });
    

    If you want to use pure JavaScript:

    var oXHR = new XMLHttpRequest();  
    oXHR.open("GET", "admin/user-count.php", true);  
    oXHR.onload = function(evt)
    {
      myGlobalVar = parseInt(oXHR.responseText,10);
    }
    oXHR.onerror = function(evt)
    {
      alert("Error!");
    }
    oXHR.send();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.