title: access return value of function from another file
body: <p>I have one js file having code as:</p>
  
  <pre><code>function postResponse(url1,param1)
  {
  var url = intranetUrl + encodeURI(url1);
  
   var xhr = new XMLHttpRequest();
      xhr.open('POST', url, true);
      xhr.onload = function(e)
      {
          if (this.status == 200)
          {
              genericRes = this.responseText;
              console.log("inside fun:"+genericRes);
              return genericRes;
          }
          alert("!!!"+this.status);
      };
  
      xhr.send(param1);
  
  
  }
  </code></pre>
  
  <p>Now from another file I want to access this function I had imported above file in this file and call function as:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
          var resss = postResponse("myURL","ACC|^ALL|^M|^|$");
          alert("genericRes"+genericRes);
          console.log("genericRes&gt;&gt;&gt;"+genericRes);
          console.log("resss&gt;&gt;&gt;"+resss); 
  
      &lt;/script&gt;
  </code></pre>
  
  <p>But here I got genericRes and resss value as undefined, and above console.log prints first and then it prints   <code>console.log("inside fun:"+genericRes);</code>  here I got correct output,  But from calling code it gives me undefined. </p>
  
  <p>In java we write suppose method which can return String as:</p>
  
  <pre><code>public String myMethod()
  {
        str = "MyString";
        return str;
  }
  </code></pre>
  
  <p>and call that method as:</p>
  
  <pre><code>String str1 = myMethod();
  </code></pre>
  
  <p>But how to do this in jquery?</p>
  
  <p>Any suggestion will be appreciated. Thanks in advance</p>