from a blade template I try to make an ajax call to an api the code I have is this
@section('custom-js')
<script type="text/javascript">
$(document).ready(function(){
alert('test');
$('#edit').on('submit',function(e){
e.preventDefault();
$.ajax({
url: '/api/v1/cars/' + $('#carId').val(),
method: 'put',
data: {
name: $('#name').val(),
},
success:function (response) {
if(response.data.data !== undefined) {
alert('ok 1');
} else {
console.log(response);
alert(response);
}
},
error:function (response) {
console.log(response.responseJSON);
$.each(response.responseJSON.errors, function(key,value) {
console.log(response.responseJSON.errors);
console.log(key);
console.log(value);
$("#" + key + "Error").css("color","red");
$("#" + key + "Error").text(value);
});
}
});
});
});
</script>
@stop
When I run the template I see the alert that says "test" but just on the back line there is the $ .ajax instruction for the "submit" event there I get this error
Uncaught TypeError: $ .ajax is not a function