BO
339 9
Asked
Viewed
513 times

I have the following voting links

<a href="#" data-comment-id="13" class="voteUp">▲</a>

<a href="#" data-comment-id="13" class="voteDown">▼</a>

And the following jQuery setting the click events to those buttons

$(document).on('click', '.voteUp', function(e) {
    e.preventDefault();
    var resourceId = $(this).data('comment-id');
    var resourceType = 'comment';
    castVote(resourceId, resourceType, 'upvote');
});

$(document).on('click', '.voteDown', function(e) {
    e.preventDefault();
    var resourceId = $(this).data('comment-id');
    var resourceType = 'comment';
    castVote(resourceId, resourceType, 'downvote');
});

If I log in in my application, go to a page where these links are and log out everything works. But if I make a vote and then log out it makes a GET request to the route('cast.vote') instead of the logout route which gives me the following error.

The GET method is not supported for route vote. Supported methods: POST.

add a comment
0

1 Answer

  • Votes
  • Oldest
  • Latest
BO
339 9
Answered

Finally found my answer. The problem is part of a middleware that I've created which redirects me to the previous page I was. The previous page I'm supposed to be redirected to is stored in a session which the log-out function uses to redirect me to after logging out. Being on a loaded page and calling an AJAX call updated the session and hitting log out sends me to the new address stored in that session.

Adding the following line of code in my middleware fixed my issue.

        if ($request->expectsJson()) {
            return $next($request);
        }
add a comment
0