Hello everyone I'm new to Laravel and I'm currently using Laravel 6.0
For some reason my javascript using @push is not working. The script only works when I paste the code in the blade file and not using the asset folder.
add.blade.php
@extends('layouts.app')
@section('content')
// Long HTML code
@endsection
@push('scripts')
<script src="{{ asset('js/position.js') }}"></script>
@endpush
layouts > app.blade.php
<main class="py-4">
@yield('content')
</main>
</div>
@stack('scripts')
</body>
public(asset) > js > position.js
$('#department').change(function(){
var departmentID = $(this).val();
if(departmentID) {
$.ajax({
type:"GET",
url:"{{url('get-section-list-position')}}?department_id="+departmentID,
success:function(res){
if(res) {
$("#section").empty();
$("#section").append('<option>Please Select Section</option>');
$.each(res,function(key, value){
$("#section").append('<option value="'+key+'">'+value+'</option>');
});
} else {
$("#section").empty();
}
}
});
} else {
$("#section").empty();
}
});
If I paste the script in the add.blade.php and used @section, it works but I'm afraid that the security of my system would be compromised. Please help.
@pushed? Do you get any errors in your browser console? Does youradd.blade.phpextendlayouts/app.blade.php?position.jsthis page is also for more stuff as well, so if you want to use it, then it will also be shown inside page view source, and maybe it may slow down your page performance as well.