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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:34:04+00:00 2026-05-29T11:34:04+00:00

I am using the following code to get a list of members and their

  • 0

I am using the following code to get a list of members and their information using ajax, jquery, php, json.
The only problem is when i use .html , it only displays the first record, it doesn’t display all of the records. Totally confused.

<script type="text/javascript">
$( document ).delegate("#member_home", "pagecreate", function() {
    var refreshId = setInterval(function(){
        var friends= new Array();
        $.ajaxSetup({cache: false})
        $.ajax({
            url:'http://www.l.example.com/app/scrip/friends_lookup.php',
            data: "",
            dataType: 'json',
            success: function(data){
                $.each(data, function(key, val) {
                    var friend = val['friend'];
                    var phone = val['phone'];
                    var status = val['status'];
                    var email = val['email'];
                    var updated = val['updated'];  
                    $('#member_friends').append("<div class='member-box'>"+friend+"<span class='status-pic1'><img src='images/"+status+".png' width='40' height='40'/></span><span class='phone_box'><a href='tel:"+phone+"'><img src='images/icons/phone.png' width='40' height='40' /></a></span><span class='email-box'><a href='mailto:"+email+"'><img src='images/mail.png' width='40' height='40' /></a></span><div class='clear'></div><span class='update-status'><i>last update:&nbsp;"+updated+"</i></span>");

                });                                             
            }                                                 
        });
    }, 1500);
});

</script>

I tried this, and it didn’t work:

<script type="text/javascript">
$( document ).delegate("#member_home", "pagecreate", function() {
    var refreshId = setInterval(function() {                                            
        var friends= new Array();
        $.ajaxSetup({cache: false})
        $.ajax({
            url: 'http://www.l.example.com/pp/scripts/friends_lookup.php',
            data: "",
            dataType: 'json',
            success: function(data){
                var output = [];
                for (var i = 0, len = data.length; i < len; i++) {
                    output[output.length] = {
                        friend  : data[i].friend,
                        phone   : data[i].phone,
                        status  : data[i].status,
                        email   : data[i].email,
                        updated : data[i].updated
                    };                                                  

                    $('#member_friends').html("<div class='member-box'>"+friend+"<span class='status-pic1'><img src='images/"+status+".png' width='40' height='40'/></span><span class='phone_box'><a href='tel:"+phone+"'><img src='images/icons/phone.png' width='40' height='40' /></a></span><span class='email-box'><a href='mailto:"+email+"'><img src='images/mail.png' width='40' height='40' /></a></span><div class='clear'></div><span class='update-status'><i>last update:&nbsp;"+updated+"</i></span>");
                }
            }
        });                                        
    }, 1500);
});
</script>
  • 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-29T11:34:05+00:00Added an answer on May 29, 2026 at 11:34 am

    You are over-writing the values each iteration of your $.each loop. Before the loop, create an array to store the data, then add to the array each iteration:

    $.ajax({
        success : function (data) {
            var output = [];
            for (var i = 0, len = data.length; i < len; i++) {
                output[output.length] = {
                    friend  : data[i].friend,
                    phone   : data[i].phone,
                    status  : data[i].status,
                    email   : data[i].email,
                    updated : data[i].updated
                };
            }
            //you now have an array of objects that each contain a set of information
        }
    });
    

    The for loop I used is quite fast, here’s a JSPerf to show the performance increase over using $.each(): http://jsperf.com/jquery-each-vs-for-loops/2

    Also you may have noticed that I used output[output.length] = ... instead of output.push(...). The former performs faster in old browsers (the latter performs faster in modern browsers), I tend to try to help the old browsers out since they really need the help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to get a list of all installed apps on
Using following code I try to get updated list of checkbuttons' corresponding text values,
I get the error list iterator not dereferencable when using the following code: bool
Im using the following code to get a bunch of information about employees from
I am using the following line of code to get a list of all
I am using the following code to get a list of the letters for
I am using following code to get bitmap from url. This function is used
I am using following code to get source for image in wpf (image is
I am using following code to get current latitude and longitude. But none of
I am using the following code to get the Google Plus posts, public class

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.