Empty textarea post with jquery ajax and formdata

1

I have a form that uses Ajax to do the POST in PHP and make the insertion in the database to get the data I use FormData however the textarea inserts empty in the bank.

<script type="text/javascript">
function submitForm() {
    var myForm = document.getElementById('cadastro_anuncio');
    var form = new FormData(myForm);

    var plano = $("#plano").val();
    if (plano != 1) {
        $.ajax({
            url: '<?php echo base_url('classificados/minhaconta/cadastrar_anuncio') ?>',
            data: form,
            type: 'post',
            processData: false,
            contentType: false,
            success:

                function (data) {
                    if (data == 0) {
                        location.reload();
                    }
                    else {
                        $("#code").val(data)
                        $("#comprar").submit();
                    }
                }
        });
        return false;
    }
}

    
asked by anonymous 12.12.2017 / 00:42

1 answer

0

According to the FormData article, the id "domain_name" should be the form. This way below.

<form id="cadastro_anuncio">
    <textarea name="myFormField"></textarea>
</form>

Also check if there is the "name" attribute in textarea.

link

    
12.12.2017 / 01:30