I have a page index.php, that has a list of data coming from the table like this
Name Age Location Action
N1 A1 L1 Add
N2 A2 L2 Add
N3 A3 L3 Add
N4 A4 L4 Add
N5 A5 L5 Add
and the code responsible for the above output is
<div id="result">
<?php foreach($data as $per_data): ?>
<div> <php echo $per_data->name; ?> </div>
<div> <php echo $per_data->age; ?> </div>
<div> <php echo $per_data->location; ?> </div>
<a href="<?php base_url(); ?>add/<?php echo $per_data->id; ?>">Add</a>
<?php foreach;?>
</div>
This page also has a search bar that helps the user to perform a search on basis of age and location. The data of this search form is submitted through ajax like this
<script type="text/javascript">
$("#search_form").submit(function(e) {
e.preventDefault();
var age = $("#age").val();
var location = $("#location").val();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "search_result",
data: { age:age, location:location },
success: function(data){
console.log(data)
$("#result").html(data);
}
});
})
</script>
After the search, the view becomes something like this
Name Age Location Action
N1 A1 L1 Add
N3 A3 L3 Add
N5 A5 L5 Add
As you can see the index page has a data and along with that it also has an "add" link, which performs some action. After the search, resulting data is displayed in the same format along with the "add" link. Now if I click on the add link, some action will be performed and that particular row will get affected, but here is the problematic area. After the link is clicked, the page gets reloaded and the div that was showing the data according to the search now is displaying the entire data that was there before the search.
I want that after the search is performed if the user clicks on the add link the row should get affected due to its action but the search result should remain the same.
So, if the search returns 3 rows and I click on any add link then after that also the same 3 rows should be displayed to the user