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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:17:29+00:00 2026-06-11T01:17:29+00:00

I currently have a dynamic number of these being generated with a foreach() loop:

  • 0

I currently have a dynamic number of these being generated with a foreach() loop:

<div id="<?php echo $data['id']; ?>" data-role="collapsible" data-theme="a">
    <h1 style="white-space: normal"><?php echo $data['text']; ?></h1>
    <center>
        <p><?php echo $data['text']; ?></p>
    </center>
</div>

What I want, is for an AJAX POST request to be dispatched to another resource with the parameters of $data['id'] when the collapsible <div> opens.

I tried using a .click method, but I was not able to make it work for a dynamic list of <div>s. I feel a method that waited until the animation was done (as to ensure the page is still responsive) is the best way.

Can someone please help with this?

  • 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-06-11T01:17:30+00:00Added an answer on June 11, 2026 at 1:17 am

    For dynamically generated content, I would suggest you use the .on() method. Take for example the following code:

    $('#container').on('click', 'div', function() {
        var id = $(this).attr('id');
        $(this).animate({
            your animation
        }, 5000, function() {
            $.ajax({
                url: "another_resource.php",
                type: "POST",
                data: {
                    id: id
                }, //data to be sent
                dataType: "text", //return data type
                async: false,
                success: function(data) {
                    console.log(data);
                },
                error: function(data) {
                    console.log(data);
                }
            });
        });
    }
    

    The first parameter is the event(s)(can be space delimited for multiple events), while the second can either be the targeted element, or the function to execute. The last, in this case, is of course the function to execute.

    The ajax will execute when the animation is complete, as requested.

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

Sidebar

Related Questions

I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
I currently have one project that currently contains multiple packages. These packages make up
I'm currently working on a project where we have a large data warehouse which
I have a string like these: String data = @<table id=_grp:CONSUMER_APPLICATION cellpadding=0 width=660> <tbody>
In the website I'm currently building we need a large number of dynamic redirects,
I have a number of tables with lots of columns that I'm using Dynamic
I use foreach to loop the array below and then making the order number
I have a dynamic 3d array of numbers and currently I'm doing it like
I have an web application with a dynamic number of tabs ranging between 2
I am currently using Dynamic Data Linq to SQL for a project. I was

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.