title: wait until function call finishes in jQuery
body: <pre><code>load_document(mobjson.ErrMsg, 1);
  </code></pre>
  
  <p>this function open create an pdf and open in new window and delete it on server everything is fine if pdf created is small but when it takes a little more time only in safari browser its execute to error:function({alert('error')}), rest of the browser is perfectly opening pdf .
  i tried </p>
  
  <pre><code>setTimeout(function () {
                              load_document(mobjson.ErrMsg, 1);
                          }, 15000);
  </code></pre>
  
  <p>but dont know how long it will take for other pdf to be create ...
  basically what i want is </p>
  
  <pre><code>load_document(mobjson.ErrMsg, 1);
  wait till its complete then execute next line ..
  </code></pre>