【问题标题】:Scripts loaded in default template not working in views in laravel 5在默认模板中加载的脚本在 laravel 5 的视图中不起作用
【发布时间】:2015-10-23 11:07:55
【问题描述】:

为什么我的 js 在 edit.blade.php 视图中不能正常工作。我的观点结构如下:

文件名:profile_main.blade.php

 @extends('layouts.main')

    @section('head')

    @yield('style') 

    @stop

    <!-- Available at the footer of page before body tag closes --> 

@section('scripts')
        <script src="{{ URL::asset('js/jquery-ui-1.11.4.custom/jquery-ui.js') }}"></script>
        <script src="{{ URL::asset('js/search.js') }}"></script>
        <script src="{{ URL::asset('js/application.js') }}"></script>
        <script type="text/javascript">
            $.ajaxSetup({
                headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
            });
        </script>
    @stop

文件名:training_main.blade.php

@extends('layouts.profile_main')

@section('style')
    <link href="{{ URL::asset('css/application/index.css') }}" rel="stylesheet">
@stop

@section('body')
    <div id="content-header">
        <img alt="user_icon" src="{{ asset('images/general/admission_page_logo.jpg') }}" class="img-responsive"/>
        <h1>@yield('page_heading')</h1>
        <h3>@yield('page_desc')</h3>
    </div>
    <hr class="header_underline"/>
    @yield('training_body')
@stop

文件名:edit.blade.php

@extends('trainings.training_main')

@section('page_heading')
    Edit Training Details
@stop
@section('page_desc')
    General
@stop

@section('training_body')

@stop

我在 application.js 中有一些 jquery 函数。我注意到这些函数在 edit.blade.php 中不起作用。例如

文件名:application.js

$("document").ready(function() { alert('Great') });

edit.blade.php 视图加载时不会发出警报。但是当我查看页面源代码时,一切似乎都加载得很好:

<!-- Javascript -->
    <script src="http://localhost:8000/js/jquery-1.11.3.js"></script>
    <script src="http://localhost:8000/js/bootstrap.min.js"></script>
    <script src="http://localhost:8000/js/main.js"></script>
        <script src="http://localhost:8000/js/jquery-ui-1.11.4.custom/jquery-ui.js"></script>
    <script src="http://localhost:8000/js/search.js"></script>
    <script src="http://localhost:8000/js/application.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({
            headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
        });
    </script>
    </body>

这可能是什么问题?我缺少什么?

【问题讨论】:

    标签: javascript php jquery laravel-5


    【解决方案1】:

    问题出在我的 js 上。我的 js 看起来像这样:

    $("document").ready(function() {
    
        limitCharacters();
        $("#edit_academic_form").on('submit', updateAcademic);
        $("#edit_training_form").on('submit', updateTraining);
    }
    

    函数 limitCharacters() 有一些语法错误,因此无法调用它下面的代码。我解决了该功能的问题,现在一切正常。

    【讨论】:

      【解决方案2】:

      在您的终端上与php artisan route:list 联系,
      在“编辑”URI 中,将显示:

      home/{home}/edit
      

      你的js没有运行的原因,为了解决这个问题你可以在你的edit.blade.php中重写js路径。

      或者如果您有其他解决方案,请告诉我。谢谢

      【讨论】:

        猜你喜欢
        • 2018-12-23
        • 2011-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多