javascript - jQuery get data from db after button clicked -
i creating button , automatically increasing value , getting current value on db.
the update value worked, value didn't update automatically after button clicked (it's updated after page has refreshed).
here jquery code:
$(document).ready(function(){ $('#like').on('click', function(e){ var id = '{{$news->id}}'; $.get('{{ url('home/like')}}/'+id, function(data){ console.log(id); console.log(data); $('#like_data').empty(); $.each(data, function(index, element){ $('#like_data').append('<p>'+element.like+'</p>'); }); }); }); });
here html code:
<form method="get"> <div id="sample-table-3"> <a id="like"><img src="/images/likes1.png" title="likes"></a> </div> </form> <div id="like_data"> <p>{{$news->like}}</p> </div>
i'm getting error this:
get http://localhost:8080/view/like/4 500 (internal server error)
xhr finished loading: "http://localhost:8080/view/like/4".
---edit: added controller , routes---
//controller public function like($id){ $news = news::find($id); $news->like += 1; $news->save(); return view('home.view')->with('news', $news); } //laravel route route::get('/home/like/{id}', 'homecontroller@like');
Comments
Post a Comment