Is my date correct?

Asked

Viewed 34 times

0

I have doubts if I am passing the data correctly by the date, is the syntax correct? I’m sending it to the.php receiver and trying to get it with POST['imagemdomeumodel']; and it doesn’t work.

$('#novo').on('submit',function(e) {
    e.preventDefault();

    form = document.getElementById('novo');
    var data = new FormData(form);
    $.ajax({
        url:'ajaxDoEnvioDeEmail.php',
        type:'post',
        data:{'imagemdomeumodelo':data},
        contentType:false,
        processData:false,
        success:function(msg) {

            console.log(msg);
            $('.envios').show();
            $('.envios').html(msg);

        },
        beforeSend: function() {
            $('.divtop').hide('fast');
            $('.carregando').fadeIn('slow');    

        },
        complete:function() {
            $('.carregando').fadeOut('slow');
        $('.sucesso').fadeIn('slow');
            $('.envios').show();
            $('.sucessow').fadeIn('fast');
        }

    });

});
  • Instead of data:{'imagemdomeumodelo':data} do so data: data

  • But I want to send you more information, like date:date+otherVariavelComNamesDoFormularioHtml

  • How to do this?

  • You can do so, as you created the variable data and its value is the interface FormData you can use the method append, see: data.append('nome', 'Fulano de Tal');, thus, it will be added in the value of the variable data as if what you put is a form element.

  • If you want to post an object in your attribute, I think you’ll need to serialize it first (take a look at this: https://www.w3schools.com/js/js_json_stringify.asp)

  • Wm Souza thanks, but I opted for another solution, I put an input Hidden and picked up bag?

  • append serves to add html element right? What is it like?

  • $( ".container" ).append( $( "H2" ) ); I have already searched here, in this case I am adding an H2 inside a div called containter.

  • There are several append, one of them is the one you quoted, used in jQuery, the one I said is specifically interface FormData, see the documentation in Português. You can also use it like this: data.append('nome', $('nome_do_campo_html').val());

Show 4 more comments
No answers

Browser other questions tagged

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