jquery - How to append data from .load() function to div using javascript? - Stack Overflow

Sorry if my question confusing, currently i got this working :success: function(json) {$('.msgWrap

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");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744080409a4555183.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信