0

i want to delete records with alert messages using javscript on my laravel view without refreshing the page.

my current code

 var dell = "Are you sure you want to delete ?";
var del_url = "{{url('destroy-shift')}}/" + json_obj[i].id;
                                                output +=

                                                        "<td></td>" +
                                                        "<td></td>" +
                                                        "<td>" + json_obj[i].START + "</td>" +
                                                        "<td>" + json_obj[i].END + "</td>" +
                                                        "<td>" + res + "</td>" +
                                                        "<td>" + json_obj[i].RUN + "</td>" +
                                                        "<td><a data-toggle='modal'  data-target='#myModal3"+xx+"' href='" + url + "' ><span class='glyphicon glyphicon-pencil '></span></a>" +
                                                        "<div class='modal fade' id='myModal3"+xx+"' role='dialog'>" +
                                                        "<div class='modal-dialog'>" +
                                                        "<div class='modal-content'><div class='modal-body'></div>" +
                                                        "</div>" +
                                                        "</div>" +
                                                        "</div>" +
                                                        "<a href='" + del_url + "' ><button type='submit' id='delete-btn' onclick='return confirm('" + dell + "')'><span class='glyphicon glyphicon-trash'></span></button></a></td>";


                                            output += "</tr>";

but still page is refreshing and im not getting the confirmation message too. plse advice

1 Answer 1

1

Use ajax call. Simply make a button and on click do the ajax call. Then in Laravel do what you want, detele, update etc...

    $('#Yourbutton').click(function() {
        $.ajax({
            url: "YourUrl",
            type: 'POST',
            success: function(){
                alert("success");
            }
        });
    });

YourUrl is url where you call your post method, so make path in your routes.php like

Route::POST('YourUrl', 'Somecontroller@Yourmethod');
Sign up to request clarification or add additional context in comments.

1 Comment

Why POST ? He is not using any form there. He is just doing the normal GET request.

Your Answer

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