admin管理员组

文章数量:1357712

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.

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.

Share Improve this question edited Dec 22, 2012 at 13:19 Eli 14.8k5 gold badges61 silver badges77 bronze badges asked Dec 22, 2012 at 12:06 user1918956user1918956 8971 gold badge8 silver badges11 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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");
    };
}
var $temp = $('<div>').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg});
$('.msgWrapper').append($temp.html()).fadeIn("slow");

I'd just send the POST request and append manually:

$.ajax({
    url: 'http://localhost:88/TicketSystem/support/ajaxmsg',
    type: 'post',
    data: {
        date: json.date,
        msg: json.msg
    },
    success: function(response) {
        $('.msgWrapper').append(response);
    }
});

Try this:

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

本文标签: jqueryHow to append data from load() function to div using javascriptStack Overflow