samedi 28 février 2015

Convert basic like function to ajax request


I have this very basic like function in my app but its not how i want it to be because every time i click the button it reloads the page, so i want to translate this codes to ajax request. but i dont know javascript or jquery.


in my Views.blade.php



<a href="{{ URL::route('like', array('id' => $posts->id)) }}" class="like">Like</a><br>


and my routes



Route::get('like{id}', array(
'uses' => 'LoginUsersController@like',
'as' => 'like'
));


and my controller



public function like($id)
{
$post = Post::findOrFail($id);
$post->likes++;
$post->save();

return Redirect::back();
}


im hoping that someone can show me how this is done in ajax request.





Aucun commentaire:

Enregistrer un commentaire