dongzhidian3538 2018-04-03 04:21
浏览 25

如果对搜索结果执行某些操作,则无法保留搜索值

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答