首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ajax在url中传递不同的链接值

如何使用ajax在url中传递不同的链接值
EN

Stack Overflow用户
提问于 2021-06-04 00:50:50
回答 1查看 28关注 0票数 1

我正在使用laravel框架和构建系统,其中用户输入标准,并从数据库中获得所有数据,这与他们在表中的搜索标准相匹配。在结果表的每一行数据中都有一个名为"request“的链接。用户单击请求链接以请求所需的项目。请求链接将特定项的in传递到后端,并更新到数据库中的表列。目前,页面每次都必须重新加载才能发出请求,这是相当烦人的。那么,我可以在不使用ajax刷新页面的情况下,通过链接动态地将i传递到我的后端吗?

这是我的观点

代码语言:javascript
运行
复制
  <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>

这是我的控制器

代码语言:javascript
运行
复制
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');


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-04 01:11:45

如下所示更改链接

代码语言:javascript
运行
复制
<td><a href="#" data-id="{{$items->id}}" class="sendRequest">Request</a></td>

在javascript中

代码语言: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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67825586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档