javascript - page redirect automatic in laravel -
i call method of controller using ajax page redirect same page controller , ajax code below
public function store(request $request) { echo "in store method"; die(); }
ajax code
$('document').ready(function () { $("#add-to-cart").click(function(){ $.ajax({ type: "post", url: '{{ route('stock_sell.store') }}', data: { "_token": "{{ csrf_token() }}" }, success:{ } }) }); });
use resource route think, doesnl't issue route. used die()
doesn't work, automaric redirect stock_sell.index
i.
presumably #add-to-cart
link, in case need use javascript prevent click event continuing load link's href. can using e.preventdefault()
:-
$("#add-to-cart").click(function(e){ e.preventdefault(); $.ajax({ type: "post", url: '{{ route('stock_sell.store') }}', data: { "_token": "{{ csrf_token() }}" }, success:{ } }) });
you can check happening opening browser's dev tools , looking @ network tab. if enable 'preserve log' option can see resources getting loaded , returning; should able see ajax call.
Comments
Post a Comment