0

I have the next JSX code

let answer = true;
var postAxios = axios({
                method: 'post',
                url:     httpLink,
                params: {table: tableName},
                data: rowInfo
               }          
              )
             .then(function (response) {
                 console.log(response);
                 alert(response);
                 answer = true;

               })
              .catch(function (error) {
                  console.log(error);
                  alert(error);
                  answer = false;
               });  
return answer;

on the final value for answer some transaction needs to be continued (answer==true) or stopped(answer==false). The problem I have is that answer is always true inclusive when the catch section is executed. Is there a way to arrange this?

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56
  • Your problem is a variation of a “classic” question that is based on a misunderstanding of how asynchronous programming works. See https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Patrick Hund May 26 '17 at 13:26
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Patrick Hund May 26 '17 at 13:27

0 Answers0