Configure axios library and read the api-key dynamically

This commit is contained in:
Nabeel Shahzad
2018-03-12 20:14:55 -05:00
parent 0f9ce8bbb9
commit 1896e1cc35
11 changed files with 1655 additions and 46 deletions

View File

@@ -1,28 +1,18 @@
@section('scripts')
<script>
$(document).ready(() => {
const select_id = "select#aircraft_select";
const destContainer = $('#fares_container');
<script>
const select_id = "select#aircraft_select";
const destContainer = $('#fares_container');
$(select_id).change((e) => {
const aircraft_id = $(select_id + " option:selected").val();
console.log('aircraft select change: ', aircraft_id);
$(select_id).change((e) => {
$.ajax({
url: "{{ url('/pireps/fares') }}?aircraft_id=" + aircraft_id,
type: 'GET',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}'
},
success: (data) => {
console.log('returned new fares', data);
destContainer.html(data);
},
error: () => {
destContainer.html('');
}
});
});
});
</script>
const aircraft_id = $(select_id + ' option:selected').val();
const url = '{{ url('/pireps/fares') }}?aircraft_id=' + aircraft_id;
console.log('aircraft select change: ', aircraft_id);
axios.get(url).then(response => {
console.log('returned new fares', response);
destContainer.html(response.data);
});
});
</script>
@endsection