Ajax problem in Laravel 5.3

0

I need help on how to save the cpf from the client to the ajax database without redirecting from the product page when ordering. follow the code I'm trying to use:

$('#add_CPF').on('submit', function(e) {
            e.preventDefault();
                $.ajax({
                    type:"POST",
                    url: "{{ route('add_cpf_cliente', Auth::user()->id) }}",
                    beforeSend: function (xhr) {
                        var token = $('meta[name="csrf_token"]').attr('content');

                        if (token) {
                              return xhr.setRequestHeader('X-CSRF-TOKEN', token);
                        }
                    },
                    data: $(this).serialize(),
                    success: function(response, data) {
                        if(response.status) {
                            $('#show_cpf_modal').modal('hide');
                            $('#buyNow').modal('show');
                        } else {
                            $('#show_cpf_modal').modal('show');
                            swal('{{ trans('general.error') }}', 'Insira um CPF válido', 'error');
                        }
                    },error:function(error){ 
                        $('#show_cpf_modal').modal('show');
                    }
                });
        });

show_cpf_modal would be where you add cpf and then open buyNow to generate the ticket.

    
asked by anonymous 06.02.2018 / 03:59

0 answers