How to replace html element with ajax response?

0 votes

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 receive the new data pulled from the database and rendered in another view which starts from ul and ends at closing ul.

How do I replace the html element from ajax response?

In ajax success function I do this:

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

Jul 7 in Web Development by kartik
• 20,470 points
61 views

1 answer to this question.

0 votes

Hello @kartik,

Assuming you are replacing your products, if you are getting formatted HTML from your controller then simply do this

success : function(response) {
$('#products').html(response);
}

No need to remove < ul > tag. You can simply replace old < li >s with new < li >s

Hope it helps!!

Thank You!!

answered Jul 7 by Niroj
• 43,540 points

Related Questions In Web Development

0 votes
1 answer

How to track with Google Analytics on a redirection page with PHP?

Hello @kartik, Since the page that is sending ...READ MORE

answered Jul 7 in Web Development by Niroj
• 43,540 points
45 views
0 votes
1 answer

How many methods of including css in an HTML document?

Hello fignithi, yes!!,you can use external file for css ...READ MORE

answered Jan 16 in Web Development by Niraj

reshown Jan 16 by Sirajul 53 views
+1 vote
2 answers

How to embed Google map on my website?

1. Search whatever you want to embed. 2. ...READ MORE

answered Jan 17 in Web Development by anonymous
112 views
0 votes
1 answer

How can i create transparency to my images?

The transparency of image can be done ...READ MORE

answered Jan 30 in Web Development by Niroj
• 43,540 points
49 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 43,540 points
1,345 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 43,540 points
118 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 43,540 points
128 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 43,540 points
1,296 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21 in Web Development by Niroj
• 43,540 points

edited Jan 21 by Niroj 66 views