Javascript 如何使用GET with laravel在搜索后清理url?

Javascript 如何使用GET with laravel在搜索后清理url?,javascript,php,laravel,eloquent,Javascript,Php,Laravel,Eloquent,我正在使用GET方法搜索数据库中的一些记录 <form id="cliente" class="form-horizontal" action="{{route('resultados_clientes')}}" method="get"> <div class="form-group row"> <label class="col-md-6 col-form-label" for="cliente"></label&

我正在使用GET方法搜索数据库中的一些记录

<form id="cliente" class="form-horizontal" action="{{route('resultados_clientes')}}" method="get">
        <div class="form-group row">
          <label class="col-md-6 col-form-label" for="cliente"></label>
          <div class="col-md-12">
            <input form="cliente" maxlength="100" autocomplete="off" class="form-control" id="cliente" type="text" name="cliente" placeholder="Introduzca el rif o nombre del cliente a buscar" required>
            <br>
            <div class="pull-right">
            <button form="cliente" class="btn btn-sm btn-info" type="submit">
              Buscar</button>
          </div>
        </div>
      </form>
我想用javascript或php在.blade中实现一种函数或类似的功能

这是我的网站

/*BUSQUEDA ESTANDAR*/
Route::namespace('Busquedaest')->group(function () {
Route::get('busqueda_est', 'BusquedaestController@index')->name('busqueda_est');
Route::get('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');
});

如果您使用的是GET方法,那么url上就会有参数。
为了不让它们可见,您应该使用POST方法。

您需要使用POST而不是GET。为此,请将html表单更改为:

<form id="cliente" class="form-horizontal" action="{{route('resultados_clientes')}}" method="post">
    @csrf
    <div class="form-group row">
      <label class="col-md-6 col-form-label" for="cliente"></label>
      <div class="col-md-12">
        <input form="cliente" maxlength="100" autocomplete="off" class="form-control" id="cliente" type="text" name="cliente" placeholder="Introduzca el rif o nombre del cliente a buscar" required>
        <br>
        <div class="pull-right">
        <button form="cliente" class="btn btn-sm btn-info" type="submit">
          Buscar</button>
      </div>
    </div>
  </form>
与:


您可以做的是对服务器进行ajax调用以获取所有记录。 使用
POST
方法可能会起作用,但它会导致每次在某些浏览器中重新加载页面时弹出对话框

根据您是否使用任何JavaScript框架,有不同的方法来实现这一点

我最喜欢的框架是VueJs,实际上我将在本周五播放一个关于如何构建搜索组件的视频流-欢迎您加入:

使用
VueJs
(甚至是纯JavaScript),您可以使用call,其外观如下:

axios.get('/your-end-point-here')
  .then(function (response) {
      // use response.data with the returned data for the list
  })
  .catch(function (error) {
      console.log(error);
  })

嗯,为什么不使用POST而不是GET?我不知道如何将我的函数更改为POST方法。我可以查看您的web.php文件吗?我会让你知道如何更改的仅供参考,你似乎缺少一个结束标记。我一直在更新我的问题@EbrahimMohammedVueJs!但有时人们希望保持简单,特别是在与简单的客户打交道时!向上投票。谢谢-当然,因此我试图找出他是否在使用任何框架,因为它也可以通过香草JS实现。我获得了这419页过期。你是否将@csrf添加到了?我的坏。。。我错过了。。。非常感谢我的朋友。。你帮了我很多
Route::get('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');
Route::post('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');
axios.get('/your-end-point-here')
  .then(function (response) {
      // use response.data with the returned data for the list
  })
  .catch(function (error) {
      console.log(error);
  })