Home jquery get return inside value to outer funtction
Reply: 0

jquery get return inside value to outer funtction

user1389
1#
user1389 Published in April 24, 2018, 6:31 am

This question already has an answer here:

  • How do I return the response from an asynchronous call? 32 answers
  • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 6 answers

My code:

function validateAddress(type){

    var status = true

    if(type == 0 || type == 2){
      $.get( "/user/status/0", function( data ) {
          if(!data.status){
            status = false
          }
          else
            status = true
        });
    }
    else{
      $.get( "/status/1", function( data ) {
          if(!data.status){
            status = false;
          }
          else{
            status = true
          }
        });
    }
    console.log(status)
    return status
  }

How to make sure the internal status is returned from function? At the moment it returns true all the time, because somehow the status value isn't changed. The AJAX part itself is working fine.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.356111 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO