1

I am trying to run 2 function where one is called inside the other.

I have a function and inside it I call a second function. I want to use the data from the second function in the first one.

function addLine() {
     if (ContagemAntesIntegracao == '' || !ContagemAntesIntegracao) {
        ContagemAntesIntegracao = 0;
    }
    var AfetaStock = '0';
    verify_serialnumbers().complete(function (data){....

and the function that is runing inside:

function verify_serialnumbers() {
  ....if (ArrayErros.length > 0) {
                set_errors(ArrayErros);
                ArrayErros = undefined;
                return;
            }
...
            var Link = $('#LINK').val() + '/?action=_ajax_inventory';
            $.ajax({
                type: 'POST',
                url: Link,
                dataType: 'json',
                placeholder: 'Lote',
                data: {
                    CheckSerialNumbers: '1',
                    CodArmazem: CodArmazem,
                    CodProduto: CodProduto,
                    CodLocalizacao: CodLocalizacao,
                    ArrayNumerosSerie: ArrayNumerosSerie,
                }
                }).done(function (response) {
                    if (response != 'ok')
                    {
                         set_errors(dados);
                    }else{
                        return ArrayNumerosSerie;
                    }
                });
        }
}

How can I continue inside the first one with an array that does not come from the AJAX call?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Alexis Garcia
  • 452
  • 3
  • 15
  • Related: https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – freedomn-m Jan 14 '20 at 14:47
  • 1
    `verify_serialnumbers` doesn't seem to return anything, so you can't call `verify_serialnumbers().complete` – VLAZ Jan 14 '20 at 14:52
  • but if i put a return it wont work with complete() either. – Alexis Garcia Jan 14 '20 at 15:14
  • Yes, you have to return something that has a `.complete` method. [Like the jqXHR object that `$.ajax()` returns](https://api.jquery.com/jQuery.ajax/#jqXHR). However, I'm not sure if that's what you intend here. – VLAZ Jan 14 '20 at 15:21
  • i want to run the function that has the ajax, and i want to keep runing acode after that function is done, thats my objective – Alexis Garcia Jan 14 '20 at 15:23

0 Answers0