Pass value to 2 different paths

Asked

Viewed 85 times

0

I would like to pass the variable var data = 'codreq=' + id; for two ways. Is that possible? If so, someone can teach me. I can only go this way:

url: "<?= base_url('coordenador/protocolo/buscaDetalhesRequerimento') ?>"

I need to move to this one at the same time:

url: "<?= base_url('coordenador/protocolo/responder_requerimento') ?>"



<script>
$(document).ready(function ()
{
    $("a#visualizar").click(function () {
        var id = $(this).attr('data-id');
        var data = 'codreq=' + id;
        //alert(data);
        $.ajax({
            type: "POST",
            url: "<?= base_url('coordenador/protocolo/buscaDetalhesRequerimento') ?>",
            data: data,
            success: function (text) {
                //if (text === "success") {
                $(".dados").html(text);
                //  });
                //window.location.reload(true);
                //}
            }
        });


    });
});

  • Why not create a function and place this AJAX code inside it and then call it twice by passing the appropriate destination URL as parameter?

  • I’m trying to do like this, but the codeigniter is fucked, I’m hitting me!

  • What appears in console.log when you call function $("a#visualizar").click()?

1 answer

0


Sending the same data to two or more requests simultaneous in the same click:

<script>
$(function () {
    $("#visualizar").click(function () {
        var id = $(this).attr('data-id');
        var url1 = '<?= base_url('coordenador/protocolo/buscaDetalhesRequerimento') ?>';
        var url2 = '<?= base_url('coordenador/protocolo/responder_requerimento') ?>';
        $.when(
            $.post(url1,{codereq:id},function(text) {
                console.log(text);
                $(".dados").html(text);
            }),
            $.post(url2,{codereq:id},function(resp2) {
                console.log(resp2);
            })
        )
    });
});
</script>
  • Gosh, you haven’t called me back yet!

  • Didn’t return what?

  • the variable date appears test but it does not send to the urls neither to 1 nor to 2 already with the ajax goes normal, only that I do not know how to go to two different urls

  • You must be doing something wrong. This: 'codreq=' + id; looks like $_GET, but you are sending data via $_POST. For $_POST the most appropriate would be var codreq = id; or codereq:id. I’ll edit the answer, but watch your code.

  • I get it, I’ll try here.

Browser other questions tagged

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