0

I want to delete my data in table without refreshing it.

Here is my view. I used href to get the specific ID and delete single row.

 @foreach ($clients as $client)
           <tr>
               <td>{{ $client->client_code }}</td>
               <td>{{ $client->client_name }}</td>

    //I want to click this then delete without refresh//
    <td><a href="/admin/clients/archTrash/{{ $client->id }}" class="btn btn-info">Active</a></td>

    //I want to click this too then delete without refresh//
    <td><a href="/admin/clients/archTrashPermanent/{{ $client->id }}" class="fa fa-trash btn btn-danger"></a></td>
           </tr>      
           @endforeach

2 Answers 2

2

Hello, jQuery - Ajax, in ajax action u can return view(), it will return compiled html and jst replace yours exists template with the incoming template. Simple example:

jQuery.ajax({
    action: '{your action}', // u can use '{{ route('route_name') }}' aswell.
    data: '{your data}', // some parameters to request send as json object incoming as array
    success: function (response) {
       console.log(response); // output of your action.
    }
});

It's is the best way to change yours content without reload. However, if you don't want to use ajax on your site, just take a look at this guide

Sign up to request clarification or add additional context in comments.

7 Comments

hey sir thanks for the answer. Im just wondering why isnt it refreshing can you try edit my code? Thanks im not that really familiar in ajax im still learning tho. Thanks
How should i call it to my href input sir?
you are welcome !!! The guide I send you can learning and writing code. I think you can try if you have a problem with ajax code you can ask)) I help you anywere
sir the guide does not help me with the deleting data.. the guide youve send to me helps pages to be dynamic not to delete. Sorry for not understanding your code again im not good in coding at ajax.
where is your controller code ? where is your ajax code or you don't have now?
|
0

jQuery's .ajax method has been deprecated by both jQuery and Browsers , you should use axios instead :

axios.delete("{{route("client.delete')}}")
.then((response) {
    console.log(response.data);
})
.catch((error) {
    console.error(error.response.data);
});

Laravel Routes:


Route::delete('/client/delete', "YourController@yourMethod")
    ->name('client.delete')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.