0

Here is my ajax code writtem in laravel framework for posting comment data. But i am getting syntax error as -

ErrorException Parse error: syntax error, unexpected 'Comment' (T_STRING), expecting ',' or ')'

for my view file.

As per my observation any jquery statement written inside success box giving me error. i am using latest version on jquery - 3.3.1.min and laravel 5.4 version.

Please support.

<script type="text/javascript">

    $(document).ready(function() {

        $("#save-comment").click(function() {

            var token = $('meta[name="csrf-token"]').attr('content');
            var comment = $('textarea#commentContent').val();
            var postId = "<?php echo $postId; ?>";

            if (comment) {
                $.ajax({
                    type: "POST",
                    url: "{{ url('/ajax/postcomment) }}",
                    data: { "_token" : token, "commentContent" : comment, "postId" : postId },
                    success: function(d) {

                        $("#notify-box").animate({ opacity: 1 }, 2000);
                        $("#notify").text('Comment Saved successfully.');

                        setTimeout(function(){
                            $('#notify-box').animate({ opacity : 0 }, 200);
                        }, 6000);

                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        $("#notify-box").animate({ opacity: 1 }, 2000);

                        $("#notify").text(errorThrown);

                        setTimeout(function(){
                            $('#notify-box').animate({ opacity : 0 }, 200);
                        }, 6000);
                    }
                });
            } else{

                $("#notify-box").animate({ opacity: 1 }, 2000);

                $('#notify').text('Add a Reply to save.');

                setTimeout(function(){
                    $('#notify-box').animate({ opacity : 0 }, 200);
                }, 6000);

            }

        });

    });
</script>

Notify box is just to display notifications, code here

<div class="notify-box" id="notify-box">
    <div class="notify-icon"><i class="fa fa-info-circle" aria-hidden="true"></i></div>
    <div class="notify-msg">
        <h4 class="">Message.!</h4>
        <p id="notify">something special done</p>
    </div>
</div>

for now view page in not getting rendered and showing error.

laravel web routes

Route::group(['prefix' => 'ajax', 'middleware' => ['auth:customer']], function () {
    if(Request::ajax()){
        //  Single post page for comments
        Route::post('/postreply', 'Blog\BlogAjaxController@ajaxPostReply');
        Route::get('/postreply', 'Blog\BlogAjaxController@ajaxGetPostReply');
        Route::post('/postcomment', 'Blog\BlogAjaxController@ajaxPostComment');
    }

});

Here is my laravel controller

public function ajaxPostComment(Request $request)

{
    $this->validate($request, [
        'comment' => 'required',
    ]);

$blogcomment = new Blogcomment();

$blogcomment->commentContent = $request->input('commentContent');
$blogcomment->postId = $request->input('postId');
$blogcomment->customerId = '1';     //  Auth::guard('customer')->id();
$blogcomment->commentStatus = 'Pending';
$blogcomment->commentType = 'Comment';
$blogcomment->commentFlag = 'Unread';
$blogcomment->like = '0';
$blogcomment->dislike = '0';

$blogcomment->save();
return response()->json([
    'status' => 'Success',
    'message' => 'Your Comment Saved Successfully.'
], 201);

}

Niks
  • 21
  • 3

0 Answers0