0

I have an insert function on my page that uses AJAX/PHP to insert data into myMySQL table, When a row of data is added, my row of data is returned and printed out inside...

 <div id="bills"></div>

I can then add another row of data, When i do this however it overwrites the contents of #bills, is there a way to add it to the information in there as opposed to overwriting that?

AJAX

function insertBill()
{
    $.post('insert_bill.php', $('form').serialize(), 
        function(data) {***
        $("#bills").html(data); 
    });
}

3 Answers 3

4
$('#bills').append(data);

jQuery.fn.append documentation

Sign up to request clarification or add additional context in comments.

Comments

2

Yes:

$("#bills").append(data);

Comments

1

Instead of .html() use .append()

$("#bills").append(data);

data can contain html tags and jQuery will do the right thing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.