singh
1 month ago
194
2
Laravel

Ajax Update - how to append a line or or insert a new line without reload

Posted 1 month ago by singh

I finally got an Ajax form submission working to edit a table row. Instead of reloading the page or using a redirect via controller I would like to show the update row in my Blade Template file.

Below is my URL for invoking the update modal and my JQuery after the success <a class="btn apland-btn btn-7 btn-sm" data-toggle="modal" data-target="#editModal" data-id="{{ $tax->id }}" data-name="{{ $tax->name }}" data-rate="{{ $tax->rate }}" data-type="{{ $tax->type }}" data-defalt="{{ $tax->default }}" > Edit </a>.

My Laravel Controller returns the JSON response: return response()->json($mycompany);

My Ajax call runs the following after the successful update:

success: function(dataResult){

var dataResult = JSON.parse(dataResult);
                           
	if(dataResult.statusCode==200){
                                    $('#editForm').modal().hide();
                                    alert('Data updated successfully !');
                                    location.reload();
                            }

}

Is there a way I can update my blade template. It shows only the following fields.

'''{{ $tax->name }}"" '''{{ $tax->type }}"" '''{{ $tax->rate }}"" '''{{ $tax->default }}""

$tax->id is the row id. It is available and used to update the record but not displayed because it is not continuous for all the users. For example - Adam can have $tax->id 2, 4,5. and Brad can have 3,7,11

Please sign in or create an account to participate in this conversation.