title: javascript variable equal to value from function
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1225667/how-to-return-ajax-response-text">How to return AJAX response Text?</a><br>
    <a href="https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a-function">How to return the response from an AJAX call from a function?</a>  </p>
  </blockquote>
  
  
  
  <p>So I have a javascript function where I'm doing an AJAX call to see if the user is online or offline. It looks something like this.</p>
  
  <pre><code>function onlineStatus(){
  
      $.ajax({
          url: "assets/ajax/online-offline.php",
          cache: false,
          success: function(html){
            return html;
          }
      }); 
  }
  </code></pre>
  
  <p>I would like to assign the value from this function as a variable that I can then use.</p>
  
  <p>Something like this.</p>
  
  <pre><code>var test = onlineStatus();
  
  if (test == "true")
     alert("online");
  else
     alert("offline");
  </code></pre>
  
  <p>Is this possible? I must be doing something wrong, but can't figure out how to achieve this result. Thanks</p>
  
  <p>// Edit:
  Thanks for your help everyone, sorry, didn't realize it may have been a duplicate question. I wasn't sure what to search for initially, so I didn't see anything related.</p>