I'm using laravel-5.3. I am trying to put some code in my blade template. But it seems that the JavaScript code is not working properly. Here is my blade template.
@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
The tagsinput is not working. what should i do. If I do this without extending any layouts it works fine. In the app layout i have yield the scripts section in the header part.
I'm using laravel-5.3. I am trying to put some code in my blade template. But it seems that the JavaScript code is not working properly. Here is my blade template.
@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
The tagsinput is not working. what should i do. If I do this without extending any layouts it works fine. In the app layout i have yield the scripts section in the header part.
Check your code by inspecting elements in developer options, see where your scripts are loading and confirm that they are included at the end of the page.
And also remember to use @endsection tag