如何将Ajax HTML响应附加到当前div旁边 [英] How to append ajax html response to next to current div

查看:75
本文介绍了如何将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以上相同,除了dividanchor tag的内容. id将是level-2level-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆