【问题标题】:My Javascript code is not running in laravel我的 Javascript 代码没有在 laravel 中运行
【发布时间】:2017-11-12 18:11:14
【问题描述】:

我正在处理一个 Laravel 项目,但我的 Javascript 代码没有措辞。我已应用警报,但未显示。当用户单击按钮时,它会显示警报,但不显示。

 @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

警报未显示。

【问题讨论】:

  • 在浏览器控制台中检查错误并粘贴到这里它将清除问题
  • 请选择帮助您解决问题的正确答案
  • 非常感谢,我得到了答案。 @Aman Attari
  • 非常感谢,我得到了答案。 @Muhammad Omer Aslam。

标签: javascript php jquery laravel-5


【解决方案1】:

确保在您的 layouts/app.blade.php 中有刀片 @yield('scripts') 标记以获取 @section('script') 刀片标记:

例子:

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

            ...

            @yield('content')

        </div>

        @yield('scripts')

    </body>
</html>

【讨论】:

  • 非常感谢。你解决了我的问题。 @开发者。
  • 你是mvp!!
猜你喜欢
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多