Edit in JSFiddle

function getUser(id) {
  var d = Q.defer() 

  $.ajax({
    url: "/echo/json/",
    data: { json: JSON.stringify({firstName: "Jose", lastName: "Romaniello"})} ,
    type: "POST"
  }).done(d.resolve).fail(d.reject);
 
  return d.promise;
}

getUser(123)
.then(function (user) {
  return Q.delay(2000)
          .thenResolve(user);
}).then(function (user) {
  alert(user.firstName);
});

              
            
          
            
              
                

              
            
          
            
              

External resources loaded into this fiddle: