Good afternoon, I'm having trouble sending data via ajax, it returns code 200 but returns
SyntaxError: Unexpected end of JSON input
But I do not think it's even in the controller
<input type="button" class="btn btn-primary btn-block" onclick="inserirContato()" value="Inserir Contato">
<script>
function inserirContato() {
var cliente = document.getElementById('cliente_id').value;
var nome = document.getElementById('nome').value;
var departamento = document.getElementById('departamento').value;
var email = document.getElementById('email').value;
var telefone = document.getElementById('telefone').value;
var celular = document.getElementById('celular').value;
$.ajax({
headers: {
'X-CSRF-Token': $('input[name="_token"]').val()
},
type: 'POST',
dataType: "json",
url: '{{ route('admin.cadastro.contatos.store') }}',
data: {
'contatable_id': cliente,
'contatable_type' : "App\Cliente",
'nome' : nome,
'departamento' : departamento,
'email' : email,
'telefone' : telefone,
'celular' : celular
},
enctype: 'multipart/form-data',
success: function(response) {
console.log(response);
},
error: function(response, textStatus, errorThrown) {
console.log(response);
},
});
}
</script>