为什么我的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>这里会有什么问题呢?我遗漏了什么?
发布于 2015-10-23 20:18:29
问题出在我的js上。我的js是这样的:
$("document").ready(function() {
limitCharacters();
$("#edit_academic_form").on('submit', updateAcademic);
$("#edit_training_form").on('submit', updateTraining);
}函数limitCharacters()有一些语法错误,因此无法调用它下面的代码。我解决了函数的问题,现在一切都很好。
发布于 2016-08-19 21:33:56
在你的终端上和php artisan route:list确认一下,
在“编辑”URI中,will显示:
home/{home}/edit这就是你的js不能运行的原因,为了解决这个问题,你可以在你的edit.blade.php中重写js路径。
或者如果你有其他的解决方案,请告诉我。谢谢
https://stackoverflow.com/questions/33300870
复制相似问题