![](/img/trans.png)
[英]Laravel 4- redirect to a route inside javascript code Blade template
[英]Javascript code is not working inside blade template Laravel
我正在使用laravel-5.3。 我正在嘗試在刀片模板中放入一些代碼。 但似乎JavaScript代碼無法正常運行。 這是我的刀片模板。
@extends('layouts.app')
@section('scripts')
<script type="text/javascript">
$(document).ready(function() {
var members = {!! json_encode($member) !!};
var arr = [];
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: members
});
cities.initialize();
var elt = $('#researcher');
elt.tagsinput({
itemValue: 'value',
itemText: 'text',
allowDuplicates: false,
interactive:true,
typeaheadjs: {
name: 'cities',
displayKey: 'text',
source: cities.ttAdapter()
}
});
console.log(members);
var elt1 = $('#advisor');
elt1.tagsinput({
itemValue: 'value',
itemText: 'text',
allowDuplicates: false,
interactive:true,
typeaheadjs: {
name: 'cities',
displayKey: 'text',
source: cities.ttAdapter()
}
});
$("#submit").click(function(event){
$.ajax({
type: "POST",
url: '/storeresearch',
data: { _token: "{{ csrf_token() }}"},
success: function( msg ) {
console.log(msg);
window.location.replace('/researches');
}
});
});
});
</script>
@endsection
@section('content')
<form id="hu" action="/storeresearch" method="POST">
{!! csrf_field() !!}
<label>Researcher</label>
<input type="text" class="R_a" id="researcher" name="researchsupervisor_1">
<label>Advisor</label>
<input type="text" class="R_a" id="advisor" name="researchsupervisor_1">
<input type="button" name="submit" id="submit" class="btn btn-primary" value="Add">
</form>
@endsection
標簽輸入不起作用。 我該怎么辦。 如果我不擴展任何布局就可以正常工作。 在應用程序布局中,我在標題部分產生了腳本部分。
通過檢查開發人員選項中的元素來檢查代碼,查看腳本的加載位置,並確認腳本是否包含在頁面末尾。
還要記住使用@endsection標記
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.