Contekan jquery ajax php
Contoh Ajax JQuery Codeigniter dan Laravel
Codeigniterurl bisa diganti GET atau POST, tergantung kebutuhan
<script>
$('#form_kelola').submit(function(e){
e.preventDefault();
var data = new FormData(document.getElementById('form_kelola'));
$.ajax({
url : '<?=base_url()?>admin/save',
type: 'POST',
data: data,
contentType:false,
processData:false,
success: function(res) {
console.log(res)
},
error: function(err) {
console.log(err)
}
});
});
</script>
Laravel
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#form_kelola').submit(function(e){
e.preventDefault();
var data = new FormData(document.getElementById('form_kelola'));
$.ajax({
url : '{{route("admin.save")}}',
type: 'POST',
data: data,
contentType:false,
processData:false,
success: function(res) {
console.log(res)
},
error: function(err) {
console.log(err)
}
});
});
</script>
Komentar
Posting Komentar