Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button does not work while visit another pagination page or being search (ajax, Laravel)

After being searched in the index page, the button action does not work. While visiting second page the action button does not work.

Here is my index page

<a href="#" class="btn btn-primary btn-active-primary btn-sm"
    data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">   
  {{actions}}

  <span class="svg-icon svg-icon-5 m-0">
     <svg xmlns="http://www.w3.org/2000/svg" width="24" </svg>
  </span>
</a>

<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded 
    menu-gray-600 menu-state-bg-light-primary fw-bold fs-7 w-125px py-4"
    data-kt-menu="true">
<div class="menu-item px-3">
    <a href="{{ route('index.show', $index->id) }}" class="menu-link 
 px-3"> 
       {{View Details}}
    </a>
</div>

Here is the Route

Route::prefix('example')->name('examples.')->group(function () {
        Route::get('', [ExampleController::class, 'index'])->name('index');
    });

Here is the script

  $(document).on("click", "#pagination a, #search_btn, #reset_btn", function() {
    if(this.id == 'reset_btn'){
        $("#searchform").reset();
    }
  $.ajax({
    url: this.dataset.url,
    type: 'get',
    data:  $("#searchform").serialize(),
    processData: false,
    cache: false,
    contentType: false,
      success: function(data) {
        $("#pagination_data").html(data); 
      },
      failure: function (response) {
          alert(response.responseText);
      },
      error: function (response) {
          alert(response.responseText);
      }        
    });
  }) 
});```
like image 746
Babur Shah Sayer Avatar asked Sep 12 '25 13:09

Babur Shah Sayer


1 Answers

Simply solve the bug by inserting the code below into the button function script.

KTMenu.createInstances();

like image 167
Babur Shah Sayer Avatar answered Sep 14 '25 04:09

Babur Shah Sayer