如何将Ajax HTML响应附加到当前div旁边 [英] How to append ajax html response to next to current div
本文介绍了如何将Ajax HTML响应附加到当前div旁边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的DOM
如下,
<div id='level-1'>
<ul>
<li><span><a>Mike</a></span></li>
<li><span><a>John</a></span></li>
<li><span><a>Ket</a></span></li>
</ul>
</div>
和jQuery
如下,
$(document).on('click','div[id^=[level] ul li span a',function(){
//Making ajax request,no problem in getting the response
// Here I need to append response next to the current div i,e div#level-1 or div#leve-2
});
ajax
的响应与DOM
以上相同,除了div
的id
和anchor tag
的内容. id
将是level-2
或level-3
,即. +1
到div的当前值.
ajax
response will be same as above DOM
except id
of the div
and content of anchor tag
. id
will be level-2
or level-3
i,e. +1
to current value of the div.
推荐答案
尝试
$(document).on('click','div[id^=level] ul li span a',function(){
var parentDiv = $(this).closest("div[id^=level]");
$.ajax(...).done(function(html) {
parentDiv.after(html);
});
});
这篇关于如何将Ajax HTML响应附加到当前div旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文