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 6533693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:09:33+00:00 2026-05-25T10:09:33+00:00

Hi guys i am retrieving data from php using ajax , what i am

  • 0

Hi guys i am retrieving data from php using ajax , what i am trying to do is first i am finding the list of online users and then based on that list i am making request to the server let say if 2 people are logged in then i am using for loop to find the numbers and then getting data for only those 2 users here’s my JS code . #name is equal to logged users name , if one user is logged in #name for that user will be 1 for other it will be 2 and so on

    $(function(){
    function liveRefresh(){
    var count = 1;

    for(x=0; x<=count; x++)
       {
    var track = $('#name' + x).val();       

    alert(track);   

    parameters = 'send_to=' + track;

        $.ajax({                
            url: "scripts/live-refresh.php", 
            type: "POST",
            data: parameters,     
            cache: false,
            success: function(html){

            alert(track);
        }
        });
    }
}

liveRefresh();

});

if i alert track variable before the ajax request it shows me all the names but after making ajax when i am alerting the same variable it says undefined.

You can try this code to see what’s happening and see if there is any way around

Thank You

  • 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-25T10:09:33+00:00Added an answer on May 25, 2026 at 10:09 am

    @3nigma to change a variable name wont help or needed, and making it global “can” help but it will be overwritten as soon as you goto the next in the loop.

    @Shanon: Im not to sure this is the best approach to do this kind of a thing. I would rather update the entire list then making a number of AJAX calls to the server.

    but if you want to run it like that, then this should work:

    $(function(){
        var callAjax = function(id) {
            var parameters = 'send_to=' + id;
    
            $.ajax({
                url: "scripts/live-refresh.php", 
                type: "POST",
                data: parameters,     
                cache: false,
                success: function(html){
                    alert(id);
                }
            });
        },
        liveRefresh = function() {
            var count = 1;
            for(var x=0;x<=count;x++) {
                var track = $('#name' + x).val();       
    
                callAjax(track);
            }
    
        };
    
        liveRefresh();
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I'm trying to write xpath or css to find/click on list element All
guys, I have the problem when copying database from local assets folder to /data/data/package_name/databases
Guys im trying to check/uncheck a checkbox based on the state check/uncheck of another
hey guys, i'm working on a rather weird ajax based search model. The search
guys, I'm trying to realize viewing comments on internet portal and I'm using UITableView.
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
guys which text editor is good for Rubyonrails? i m using Windows and i
Guys, I am using dynamic programming approach to solve a problem. Here is a
Guys that is code copied from a book (Programming Windows 5th edition): #include <windows.h>
Guys, I'm trying to finish up my homework but I'm having some problems here

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.