2 years ago

Show Single post in laravel with ajax call

Posted 2 years ago by beginner_luck

Hello can someone help me through this, I want to show the data of my single post, let say I have a list of post and there was a button on it as "VIEW", when I click the button the single post will then show and hide the table/list of post.

View Button:

                            <button class="show-post btn btn-success" data-id="{{$post->id}}" data-title="{{$post->title}}" data-slug="{{$post->slug}}" data-category="{{$post->category_id}}" data-image="{{$post->image}}" data-body="{{$post->body}}">
                                <span class="glyphicon glyphicon-eye-open"></span> View</button> 
                            <button class="edit-post btn btn-info" data-id="{{$post->id}}" data-title="{{$post->title}}" data-slug="{{$post->slug}}" data-category ="{{$post->category_id}}" data-image="{{$post->image}}" data-body="{{$post->body}}">
                                <span class="glyphicon glyphicon-edit"></span> Edit</button>


the data will show in this button, but when I click the VIEW button, it showed me a wrong data in the single post.

My Code for displaying the single post: $(document).on('click', '.show-post', function() {

        var id = $(this).attr('data-id');
        var title = $(this).attr('data-title');
        var slug = $(this).attr('data-slug');
        var category = $(this).attr('data-category');
        var featured_image = $(this).attr('data-image');
        var body = $(this).attr('data-body');


Please sign in or create an account to participate in this conversation.