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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:28+00:00 2026-05-27T11:32:28+00:00

I have an ajax function that sends a variable – num – to a

  • 0

I have an ajax function that sends a variable – num – to a php script and then echos the value of num in a div with id “status”.

First what happens is the user makes a post, i run all the necessary queries and display the users posts in a div called “posts” (use a while loop so each post is in a div with the same id but the div’s are under one and other). I would like the ajax functionality to work in every one of these “posts” divs (each “posts” div contains the two js buttons witch – onclick – manage the ajax function as well as a “status” div)

However every time i click one of the buttons, lets say in the bottom most visible “posts” div displayed (the button clicked calls the ajax/js function), the function carries out in the top most “posts” div where the first “status” div is whereas it should be displaying in the bottom most div where i clicked the button.

  • 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-27T11:32:29+00:00Added an answer on May 27, 2026 at 11:32 am

    EDIT: Sorry, I was assuming you were using jQuery. My bad.

    You should be using classes instead of IDs. If you use an ID jquery will only have an effect on the first one in the DOM. IDs should only be used once per page.

    Use classes, then reference the divs you want to edit not only by class name, by some sort of reference to the post div you are interacting with.

    $('.posts .button').click(function() {
      //do ajax stuff...
      $(this).parent('div').find('.status').html(data);
    }
    

    Updated code:

    // .posts should be the class of the posts div
    // .button should be the class of the button on which you are activating your ajax
    $('.posts .button').click(function() { 
        $.post('your ajax post URL', function(data) {
           $(this).parent('div').find('.status').html(data);
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery-ajax function that sends data to a php script and the
I have jQuery Ajax request that sends data to a PHP page that then
I have some jQuery code. I have called an Ajax function file, file.php, that
Hey guys I have an ajax jquery function that receives data from a php
I have a small JS function that does Ajax for me and another like
I have a javascript function that calls a generic function to make an ajax
I have the following function that is pulling data from a database. The ajax
I have the following code that works on Firefox and Chrome $("#adicionarItem").click(function(){ $.ajax({ type:
I have a contact form i want to use Ajax for. My contact.php script
I have the below jquery function $(function(){ $(select#rooms).change(function(){ $.getJSON(/admin/select.php,{id: $(this).val(), ajax: 'true'}, function(j){ var

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.