dpz
dpz

Reputation: 79

How to show data from database with jquery?

its my first week learn jquery and i use this jquery to insert multiple rows on my page

$(document).ready(function() {
        var count = 0;

        $("#add_btn").click(function(){
                count += 1;
            $('#container').append(
                         '<tr class="records">'
                     + '<td ><div id="'+count+'">' + count + '</div></td>'
                     + '<td><input id="task_' + count + '" name="task_' + count + '" type="text"></td>'
                     + '<td><input id="person_' + count + '" name="person_' + count + '" type="text"></td>'
                     + '<td><input id="time_' + count + '" name="time_' + count + '" type="text"></td>'
                     + '<td><a class="remove_item" href="#" >Delete</a>'
                     + '<input id="rows_' + count + '" name="rows[]" value="'+ count +'" type="hidden"></td></tr>'
                );
            });

            $(".remove_item").live('click', function (ev) {
            if (ev.type == 'click') {
            $(this).parents(".records").fadeOut();
                    $(this).parents(".records").remove();
        }
        });
    });

this how i load jquery on my page

<table>
        <tr>
        <td><input type="button" name="add_btn" value="Add" id="add_btn"></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
    </tr>
        <tr>
            <td>No</td><td>Task</td><td>Person Responsible</td><td>Due Date</td><td>&nbsp;</td>
        </tr>
        <tbody id="container">

    </tbody>
    <tr>
      </tr>
    </table>

but i want change the person row'<td><input id="person_' + count + '" name="person_' + count + '" type="text"></td>' to show the list data of person from my database

can someone give me example how to do that? i using codeigniter to build this

Upvotes: 0

Views: 1238

Answers (1)

linnkb
linnkb

Reputation: 525

You can use jquery.get() (or $.ajax(), see example) to make a call to a method on your server. The requested method on your server collects the data from the database and pass it on to the jquery.get() function. If the data you return is in json format, you can use jquery.getJSON() instead.

Upvotes: 1

Related Questions