I am making a like button to like the post. I want to show the counter of likes without the page being reloaded. I am very new to ajax. Can someone please tell me the the script and the function and the view.
I have created small function which helps me every time I want to send ajax.
function ajaxCall(url, data, method = "post") {
data._token = '{{ csrf_token() }}';
$.ajax({
url: url,
method: method,
data: data
}).done(function(resp) {
//Do Your Code
}).fail(function (resp) {
//Do Fail Code
});
}
If you want to use ajax post with laravel you should send _token
with data. If it's get method than you can not pass _token
to ajax call... You can create route and try this function out.