如何使用javascript将.load()函数中的数据附加到div?
很抱歉,如果我的问题让人困惑,目前我正在工作:如何使用javascript将.load()函数中的数据附加到div?,javascript,jquery,Javascript,Jquery,很抱歉,如果我的问题让人困惑,目前我正在工作: success: function(json) { $('.msgWrapper').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg}).fadeIn("slow"); } 但是这只是用.load()函数返回的数据替换我的div的内容,我想将数据附加到我的div中,而不是仅仅替换
success: function(json) {
$('.msgWrapper').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg}).fadeIn("slow");
}
但是这只是用.load()函数返回的数据替换我的div的内容,我想将数据附加到我的div中,而不是仅仅替换。
提前感谢。var$temp=$('').load('')http://localhost:88/TicketSystem/support/ajaxmsg“,{date:json.date,msg:json.msg});
var $temp = $('<div>').load('http://localhost:88/TicketSystem/support/ajaxmsg', {date: json.date, msg: json.msg});
$('.msgWrapper').append($temp.html()).fadeIn("slow");
$('.msgWrapper').append($temp.html()).fadeIn(“慢”);
您可以使用jQuery AJAX速记方法获取数据,然后只需附加到元素:
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");
};
}
success:function(json){
$.post($)http://localhost:88/TicketSystem/support/ajaxmsg“,{date:json.date,msg:json.msg},函数(数据){
var newData=$('').html(数据);
$('.msgWrapper')。追加(新数据);
newData.hide().fadeIn(“慢”);
};
}
我只需发送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");
$(.msgWrapper”).append($(“”).load('http://localhost:88/TicketSystem/support/ajaxmsg“,{date:json.date,msg:json.msg}).fadeIn(“慢”);
太棒了,因为我在一篇ajax文章中获得了成功函数,所以这篇文章非常好用。无论如何,我从来没有得到过。fadeIn()要工作,有什么建议吗?你是想淡入.msgWrapper
还是想淡入刚刚附加的.msgWrapper
中的元素?我只想淡入刚刚附加的数据。我已经更新了答案,将附加的内容包装在一个
中,然后淡入。非常完美,谢谢大家oby,对不起,我没有足够的声誉来支持这个。