JQuery ajax send data

I have a problem sending an option selected using ajax.

Code

$("#editarConta").on('submit',(function(e) {

        e.preventDefault();

        $.ajax({
            url: "includes/php/class_conta.php",
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            success: function(resultado){
                $("#accountEdit_result").html(resultado);
            }
        });

    }));

Sending this data I do not see which option was selected. Is there any way to send this data, plus the selected option:

data: { new FormData(this) , optionSelected: $( "#linguagem_favorita option:selected" ).val() },

My highlighted HTML :

<select name="linguagem_favorita" id="linguagem_favorita" class="form-control">

If I send with my code, I get NULL when I var_dump the variable

var_dump($_POST["linguagem_favorita"]);
+4
source share
1 answer

Add to form data:

$("#editarConta").on('submit',(function(e) {

    e.preventDefault();

    var formData = new FormData(this);
    formData.append("optionSelected", $("#linguagem_favorita option:selected" ).val() );

    $.ajax({
        url: "includes/php/class_conta.php",
        type: "POST",
        data: formData,
        contentType: false,
        cache: false,
        processData:false,
        success: function(resultado){
            $("#accountEdit_result").html(resultado);
        }
    });

}));
+3
source

Source: https://habr.com/ru/post/1611617/


All Articles