【问题标题】:How to pass the different link values in url using ajax如何使用ajax在url中传递不同的链接值
【发布时间】:2021-08-21 19:41:36
【问题描述】:

我正在使用 laravel 框架并构建用户输入条件并从数据库中获取与表中搜索条件匹配的所有数据的系统。在每行数据的结果表中都有一个名为“请求”的链接。用户单击请求链接以请求所需物品。请求链接将特定项目的 ID 传递到后端并更新到数据库中的表列。目前,页面每次都必须重新加载才能发出请求,这很烦人。那么,我可以在不使用 ajax 刷新页面的情况下通过链接动态传递 ids 到我的后端吗?

这是我的观点

  <div class='container' style="margin-top:50px">
        <div class="row">
    
      

      <div class="input-group" style="margin:20px">
        <form >
          <table style="float:right">
            <th>
                <div class="form-outline">
                    <input type="search" id="form1" class="form-control" placeholder="Search" /></th>                        
                      <th><button type="button" class="btn btn-success" >
                      <i class="fas fa-search"></i>
                        </button></th>
          
  </form>
</div>


      <div class="table-responsive">

        <table class="table custom-table">
          <thead>
            <tr>
              <th scope="col">
                <label class="control control--checkbox">
                  <input type="checkbox" class="js-check-all"/>
                  <div class="control__indicator"></div>
                </label>
              </th>
              <th scope="col" >S.N</th>
              <th scope="col">LC NO</th>
              <th scope="col">Applicant</th>
              <th scope="col">Doc Value</th>
              <th scope="col">Doc Received date</th>
              <th scope="col">LC Type</th>
              <th scope="col">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php $number = 1;?>
            @foreach($datas as $items)
              
            <tr>
              <th scope="row" style="padding:20px">
                <label class="control control--checkbox">
                  <input type="checkbox"/>
                  <div class="control__indicator"></div>
                </label>
              </th>
              <td>{{$number}}</td>
              <td>{{$items->lc_no}}</td>
              <td>{{$items->applicant}}</td>
              <td>{{$items->doc_value}}</td>
              <td>{{$items->rec_date}}</td>
              <td>{{$items->sight_usance}}</td>
              <td><a href="maturity_reqController/{{$items->id}}">Request</a></td>
              <td><a href="/hold_req/{{$items->id}}">Hold</a></td>
            </tr>
            <?php $number++; ?>
            @endforeach
         
            
          </tbody>
        </table>
      </div>


    </div>

  </div>

这是我的控制器

function maturity_reqController($id){
    $forset = new Settlement();
    $forset->org_document_id = $id;
    $forset->save();

 $data = Doc::find($id);
 $data->status = "Maturity Requested";
 $data->save();
 return redirect('maturity_settlement');


}

【问题讨论】:

    标签: jquery ajax laravel laravel-8


    【解决方案1】:

    如下更改链接

    <td><a href="#" data-id="{{$items->id}}" class="sendRequest">Request</a></td>
    

    在javascript中

    <script>
    $('.sendRequest').on('click',function(){
        
        var id=$(this).attr('data-id')
        $.ajax
    ({
      type: "GET",
      url: "maturity_reqController/"+id,
    
      success: function(response)
      {
         alert(response);
      }
    });
    
    })
    
    </script>
    

    【讨论】:

    • 它有效,但是...我需要在更新时将其从列表中隐藏...
    • 那么您需要使用 jquery 根据您选择的行隐藏
    猜你喜欢
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 2016-08-26
    • 2016-08-10
    • 2019-12-31
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多