Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append data from .load() function to div using javascript?

Sorry if my question confusing, currently i got this working :

success: function(json) {
            $('.msgWrapper').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg}).fadeIn("slow");
        }

But this only replace my div's content with the data returned by the .load() function, i want to append the data to my div instead of just replacing. Thanks in advance.

like image 740
user1918956 Avatar asked Apr 25 '26 12:04

user1918956


2 Answers

You can use the jQuery AJAX shorthand post method and to get the data, then just append to your element:

success: function(json){
    $.post('http://localhost:88/TicketSystem/support/ajaxmsg', { date: json.date, msg: json.msg }, function(data){
        var newData = $('<div>').html(data);
        $('.msgWrapper').append(newData);
        newData.hide().fadeIn("slow");
    };
}
like image 80
Dan Ellis Avatar answered Apr 28 '26 03:04

Dan Ellis


var $temp = $('<div>').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg});
$('.msgWrapper').append($temp.html()).fadeIn("slow");
like image 32
Sanjeev Avatar answered Apr 28 '26 03:04

Sanjeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!