javascript - Call a method when another one finishes -


i have function in javascript consists of ajax call. let's call search();

then have event onkeyup.

in onkeyup event, have enterpressed() function.

i want call function after search() finishes.

i think callbacks won't here.

here's code:

function search () {        ... }  ed.onkeyup.add(function (ed, e) {      if (e.keycode == 13)                 enterpressed();  }  function enterpressed() {        ... } 

callbacks way forward.

either:

  1. bind keyup event handler in callback fires when search finishes or
  2. set variable (in scope both functions) , change value when search finishes. before doing in keyup handler, check value and, if hasn't changed, return immediately.

(this assumes calling of enterpressed keyup function significant. if including of keyup code red herring shows want call @ other time as well then use callback directly).


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -