如何使用Ajax响应取代HTML元素? [英] How to replace html element with ajax response?

查看:88
本文介绍了如何使用Ajax响应取代HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更换从Ajax响应的HTML元素?我所知道的就是要删除的元素,我怎么替换删除标签与Ajax响应? 例如:

我有code是这样的:

 < UL ID =产品>
...............
< / UL>
 

当我点击一个按钮,AJAX调用到codeginter控制器在那里我收到来自数据库的新数据拉升,而在另一个视图,它开始从UL和结束于关闭UL呈现。

在阿贾克斯成功的功能我这样做:

  $('#产品)删除();
//做什么,现在这里与阿贾克斯的响应更换去除部分?
 

解决方案

您可以使用replaceWith(参见: HTTP://api.jquery .COM / replaceWith /

我爱: $('#产品)replaceWith(响应);

How do I replace the html element from ajax response? What I know to is to remove the element, how do I replace that removed tag with ajax response? For example:

I have code like this:

<ul id="products">
...............
</ul>

When I click on a button the ajax call is made to codeginter controller where I recieve the new data pulled from the database and rendered in another view which starts from ul and ends at closing ul.

In ajax success function I do this:

$('#products').remove();
//What to do now here to replace the removed portion with response of ajax?

解决方案

You can use replaceWith (see: http://api.jquery.com/replaceWith/)

Like: $('#products').replaceWith(response);

这篇关于如何使用Ajax响应取代HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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