Empty textarea post with ajax jquery and formdata

Asked

Viewed 169 times

1

I have a form that uses Ajax to do the POST in PHP and insert in the database to get the data using Formdata but the textarea inserts empty in the database.

<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;
    }
}

1 answer

0

According to Article Formdata, the id "cadas_anuncio" must be the form. Thus below.

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

Also check for the "name" attribute in the textarea.

https://codepen.io/anon/pen/XVrvQj

Browser other questions tagged

You are not signed in. Login or sign up in order to post.