Send two data through ajax

0

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

$('#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 code above I get an array list and display in #result. How do I send this result to another page along with the response of a form?

        $('#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 is the part where I send a second form ... But how do I send what's in the div #result together?

    
asked by anonymous 08.12.2018 / 04:46

1 answer

0

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

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

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

data: {dados, id: id},
    
08.12.2018 / 23:13