Send two data via ajax

Asked

Viewed 109 times

0

Next, I have an ajax code that takes values from a form and sends it to a page. But I need to send together a return that I have already obtained in an ajax passage.

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

          var dados = new FormData(this);

          $.ajax({
            contentType: "charset=UTF-8",
            url: 'buscar.php',
            type: "POST",
            dataType:"html",
            data: dados,
            processData: false,
            cache: false,
            contentType: false,

            success: function (data) {              
              $('.primeira').hide();
              $('.segunda').show();
              $('#resultado').html(data);
            }
        });
        return false;
    });

This above code I get an array list and display in the result #. How I send this result to another page along with a form reply?

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

        var dados = new FormData(this);
        var id = $('#resultado').val();

        $.ajax({
        contentType: "charset=UTF-8",
        url: 'lista.php',
        type: "POST",
        dataType:"html",
        data: {dados, id},
        processData: false,
        cache: false,
        contentType: false,

        success: function (data) {
            $('.segunda').hide();
            $('#resultado').html(data);
            $('.terceira').show();            
        }
        });
        return false;
});

Here above is the part where I send a second form... However how to send what is in the div #result together?

1 answer

0

Like the first Ajax you used $('#resultado').html(data);, it is assumed that the element #resultado be a div (or other element that accepts internal content). Therefore, in the second Ajax you should use the same method .html() to get this content, ie:

var id = $('#resultado').html();

And in the data, pass this value in the parameter id:

data: {dados, id: id},

Browser other questions tagged

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