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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:55:47+00:00 2026-06-04T13:55:47+00:00

I made an ajax form with json response. The json array contains information out

  • 0

I made an ajax form with json response. The json array contains information out of a mysql database. Now I want to show these datas in a table.

I made a placeholder in the html file which is hidden.

Here my Code for the ajax/json part:

$("#select_coffee_talk_year").button().click(function() {
    var form = $('#coffee_talk_year');  
    var data = form.serialize();

    $.ajax({
        url: "include/scripts/select_event.php",
        type: "POST",
        data: data,
        dataType: 'json',
        success: function (select) {
            //alert(select.ID[0]);
            //alert(select.ID[1]);
            //alert(select.ID.length);


            $("#coffee_talk").fadeOut();
            $("#coffee_talk").fadeIn();
        }   
    });
    return false;
});

This is my html:

<p class="bold underline headline">Bereits eingetragen:</p>
    <form id="coffee_talk_year" action="include/scripts/select_event.php" method="post" accept-charset="utf-8"> 
        <select name="year_coffee_talk" id="year_coffee_talk">
            <option value="none" class="bold italic">Jahr</option>
            <?php
                for($i=2008; $i<=$year; $i++){
                    if ($i == $year) {
                        echo "<option value=\"".$i."\" selected=\"$i\">".$i."</option>\n";
                    } else  echo "<option value=\"".$i."\">".$i."</option>\n";
                }   
            ?>
        </select>
        &nbsp;&nbsp;
        <button id="select_coffee_talk_year">anzeigen</button>
        <input type="hidden" name="coffee_talk_year_submit" value="true" />​​​​​​​​​​​​​​​​​
    </form>
    <br />
    <div id="coffee_talk"></div>
    <br />
    <button id="add_coffee_talk">hinzufügen</button>

select_event.php:

if ('POST' == $_SERVER['REQUEST_METHOD']) {
    /*******************************/
    /** Erzaehlcafe auswählen
    /*******************************/
    if (isset($_POST['coffee_talk_year_submit'])) {
        $getID = array();
        $getDate = array();
        $getTheme = array();
        $getContributer = array();
        $getBegin = array();
        $getPlace = array();
        $getEntrance = array();
        $getFlyer = array();

        $sql = "SELECT 
                    ID,
                    Date,
                    Theme,
                    Contributer,
                    Begin,
                    Place,
                    Entrance,
                    Flyer
                FROM 
                    Coffee_talk
                WHERE
                    YEAR(Date) = '".mysqli_real_escape_string($db, $_POST['year_coffee_talk'])."'
                ";

        if (!$result = $db->query($sql)) {
            return $db->error;
        }

        while ($row = $result->fetch_assoc()) {
            $getID[$i] = $row['ID'];
            $getDate[$i] = $row['Date'];
            $getTheme[$i] = $row['Theme'];
            $getContributer[$i] = $row['Contributer'];
            $getBegin[$i] = $row['Begin'];
            $getPlace[$i] = $row['Place'];
            $getEntrance[$i] = $row['Entrance'];
            $getFlyer[$i] = $row['Flyer'];
            $i++;
        }

        $result->close();

        $response['ID'] = $getID;
        $response['Date'] = $getDate;
        $response['Theme'] = $getTheme;
        $response['Contributer'] = $getContributer;
        $response['Begin'] = $getBegin;
        $response['Place'] = $getPlace;
        $response['Entrance'] = $getEntrance;
        $response['Flyer'] = $getFlyer;

        echo json_encode($response);
    }
}

Div with id=coffee_talk is my placeholder. Now I wish to fade in the table with its data and if I change the year and submit it with the button I wish to fade the old one out and fade new in.

My only problem is that I need to write this table in php with loops. But I think its not possible in Java Script. What should I do?

PS I used ajax cause I dont want to have a reload all the time.

  • 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-04T13:55:49+00:00Added an answer on June 4, 2026 at 1:55 pm

    Your quick solution would be:

    $("#select_coffee_talk_year").button().click(function() {
        var form = $('#coffee_talk_year');  
        var data = form.serialize();
    
        $.ajax({
            url: "include/scripts/select_event.php",
            type: "POST",
            data: data,
            dataType: 'json',
            success: function (select) {
                var coffee_talk = $("#coffee_talk");
                coffee_talk.fadeOut('fast', function() {
                    for(i in select) {
                        row = select[i];
                        div = coffee_talk.append('<div id="row_'+i+'" />');
                        for(column in row) {
                           div.append('<span class="column_'+column+'">'+row[column]+'</span>');
                        }
                    }
                    coffee_talk.fadeIn();
                });
            }   
        });
        return false;
    });
    

    For a nicer approach you should lookup Moustache.js which is a client side JavaScript templating engine (which has equivalents in PHP/Java/Ruby/Python/Go and other languages and is based on Google CTemplates).

    It will allow you to create HTML templates and populate them with the data you have in a variable such as the JSON variable an AJAX request might receive.

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

Sidebar

Related Questions

I have a form I'd like to submit as JSON via jQuery AJAX, so
I have made a clock to show current time with an ajax timer in
I made a form with ajax email validation. My problem is that I need
I've got this form, initialized from the data in a Mysql database entry. If
I've made an ajax search form that brings up results onkeyup, that works well.
I have made an AJAX chat using Javascript, PHP, and MySQL. I send the
Im opening a form via ajax (using jquery) and i want to save it
I've made a login that uses ajax to send the form to a php
I made some ajax sites in the past where I used ajax to get
i'm working on a project which works very much with ajax (made via jquery).

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.