0

I am working on a Laravel project and my Javascript code is not wording. I have applied the alert and it is not showing. When the user will click the button it will show the alert and it is not showing.

 @extends('layouts.app')

 @section('content')
 <div class="container">
   <div class="row">
    <div class="col-md-8 col-md-offset-2">
        <div class="panel panel-default">
            <div class="panel-heading">Dashboard

            <button id="read-data" class="btn btn-info pull-right btn-xs">Load Data By Ajax</button>
            </div>

            <div class="panel-body">
            <table class="table table-bordered table-striped table-condensed">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Full Name</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>

                    </tr>
                </tbody>
            </table>
            </div>
        </div>
    </div>
   </div>
   </div>
       @endsection

       @section('script')

     <script type="text/javascript" charset="utf-8">
      $('#read-data').on('click', function(){

      alert('sdsdsd');

      });
       </script>


    @endsection

The alert is not showing.

4
  • check error in browser console and paste here It will clear the issue Commented Nov 12, 2017 at 18:23
  • do select the right answer that helped you solve the peoblem Commented Nov 12, 2017 at 18:25
  • Thank You So Much, I got my answer. @Aman Attari Commented Nov 12, 2017 at 18:36
  • 1
    Thank You So Much, I got my answer. @Muhammad Omer Aslam. Commented Nov 12, 2017 at 18:37

1 Answer 1

5

Make sure that in your layouts/app.blade.php you have the blade @yield('scripts') tag to pick up the @section('script') blade tag:

Example:

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
    <head>
        ...
    </head>
    <body>
        <div id="app">

            ...

            @yield('content')

        </div>

        @yield('scripts')

    </body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You Very Much. You solved my Problem. @developernator.
you are the mvp!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.