title: Nesting promises: make two promise calls back to back, passing values
body: <p>I am currently building a license system for my electron applications. But I haven't been successful with the following:</p>
  
  <ol>
  <li>Make a promise to prompt user for input (electron-prompt module)</li>
  <li>Make an ajax call to server right after</li>
  <li>Evaluate response (either a 1\n or 0\n from server-side script) </li>
  </ol>
  
  <p>The headache comes to running the ajax call after getting the userinput from prompt (which is structured as a promise) and actually wait for it to finish.</p>
  
  <p>Until now, I have tried to restructure my promises, as such:</p>
  
  <p>(1)</p>
  
  <pre><code>prompt().
    then(ajax()).
      then(evaluate()).
        catch()
  </code></pre>
  
  <p>(2)</p>
  
  <pre><code>prompt().
    then(ajax().
           then(evaluate())).
      catch()
  </code></pre>
  
  <p>This is currently where i am, where the ajax function does not return anything to pass on.</p>
  
  <p>First is the prompt, which works accordingly, returning its value.</p>
  
  <pre><code>function activeValidation(){
      try{
          prompt({
              title: "Enter key",
              label: "Enter your key",
              value: "",
              alwaysOnTop: true,
              autoHideMenuBar: true,
              inputAttrs: {
                  type: 'text'
              },
              type: "input"
          })
  </code></pre>
  
  <p>Headache is within this segment, the ajax one.</p>
  
  <pre><code>        .then(function(userinput){
              return new Promise(function(resolve,userinput){
              var req = new XMLHttpRequest();
              req.onreadystatechange = function(){
                  if(req.readyState == 4 &amp;&amp; req.status == 200){
                      resolve(req.responseText);          
                  }
              }
              req.open("GET","someCGIscript?key="+userinput,true);
              req.send();
              }).then(function(response){
                  if(response == "1\n"){
                      runProgram();
                  }
                  else{
                  }
          }).catch(function(e){
              console.error(e);
              terminate();
          })});               
      }
      catch(e){
          console.log(e.name);
          console.log(e.message);
          terminate();
      }
  }
  </code></pre>
  
  <p>I have tried printing the value of the ajax Promise from <code>resolve(req.responseText);</code> but returns undefined in the following segment.</p>
  
  <p>After that I tried to restructure the two promises (nested and as .then of the first promise), no luck.</p>
  
  <p>I believe this is a matter of structuring the promises correctly, but I am still a novice to Promises, atleast in js :).</p>