Skip to content

Instantly share code, notes, and snippets.

@Sean-Spallen
Created May 10, 2019 08:43
Show Gist options
  • Save Sean-Spallen/adb9383dd6da92b93e16e3e422319007 to your computer and use it in GitHub Desktop.
Save Sean-Spallen/adb9383dd6da92b93e16e3e422319007 to your computer and use it in GitHub Desktop.
Laravel - AJAX Request
<script src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script>
jQuery(document).ready(function(){
jQuery('#ajaxSubmit').click(function(e){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/grocery/post') }}",
method: 'post',
data: {
name: jQuery('#name').val(),
type: jQuery('#type').val(),
price: jQuery('#price').val()
},
success: function(result){
console.log(result);
}});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment