简体   繁体   English

如何使用javascript将.load()函数中的数据附加到div?

[英]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. 但这只是 .load()函数返回的数据替换我的div的内容,我想数据附加到我的div而不是替换。 Thanks in advance. 提前致谢。

You can use the jQuery AJAX shorthand post method and to get the data, then just append to your element: 您可以使用jQuery AJAX速记post方法获取数据,然后只需附加到您的元素:

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: 我只是发送POST请求并手动追加:

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

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM