Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

Ajax: Function specified in route is not called

$
0
0

I have a button that when you click it, it will show a confirmation box. If the user clicks 'ok', the word 'reached' would display inside of the div named 'EventData'.

So far the confirmation box shows when I click the button but 'EventData' won't show the word 'reached' when I confirm it.

*the 'event_id' has a value

I think the problem is with the url part where it won't go in the function

Route:

Route::post('/ArchiveEventPosts','AdminController@ArchiveEventposts')->name('ArchiveEventposts');

Script:

$(document).on('click', '.archive', function() {

    var event_id = $(this).attr('event_id');

    var x = confirm("Are you sure you want to archive this record?");

    if (x) {

        $.ajax({
            method: "POST",
            url: '{{ route("ArchiveEventposts") }}',
            data: {
                event_id: event_id
            },
            success: function(data) {
                $('#EventData').html(data);
                alert('Record Archived');
            }
        });
    }
});

Function in the controller:

public function ArchiveEventposts(Request $request)
{
   echo 'Reached';
}

Viewing all articles
Browse latest Browse all 138221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>