SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Technographs's Avatar
    Join Date
    Jan 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Multiple Ajax calls in a loop with PHP

    Hi,

    I am developing a application having a button "GetALL" with the click on this button multiple Ajax calls will be done. What i am trying to figure out that should i make all these ajax calls in FOR LOOP. Will it not slow down the process ? is it not a good way to call multiple AJAX page ? What is the best/optimal way to achieve this ?

    Basically, i need to check that whether multiple Users are online or not with these ajax calls.

    Please Suggest.

    Thanks
    Technographs

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you just get all data in one call?

  3. #3
    SitePoint Enthusiast Technographs's Avatar
    Join Date
    Jan 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    why don't you just get all data in one call?
    well, i need to fetch the status from one of my own website with passing a unique parameter for each User so that why i can not do this on one single call. Also, i need to show their status individually as i get the status (online or offiline).

    Actually this is the Admin Panel where a list of users are showing. I want to provide a button to Administrator by clicking on it, status will show in front of each username one by one.

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand.
    you need to get status of, say 10 users from one site.
    why don't you get it with one request?
    you can get an array, with unique parameters for each User. no problem

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to do it with a single call.
    With your list (or table) of users showing on the page you should put some unique identifier in the markup. Then when you handle the click event capture all the user IDs and wrap them to send off on the Ajax request.
    Code HTML:
    ...
    <tr id="user_5"><td>Bob</td></tr>
    <tr id="user_12"><td>Ben</td></tr>
    <tr id="user_46"><td>Barry</td></tr>

    The server side Ajax handler can then do something with that array. If you're getting the data from a DB, the query will be along the lines of:
    Code SQL:
    SELECT online FROM users WHERE userID IN (5, 12, 46)

    The response will probably be a JSON encoded array, with each user ID and the status information then you can loop over again and update the DOM with.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •