0

I'd like to call a javascript (with jQuery) function after one has completely ended.

I know there's a way to do it using the $.ajax() function with the 'success:' parameter. Is there a way to do the same thing without using the $.ajax() function ?

For example if I had :

var test = function()
{
    alert('Hello !');
}

var test_check = function()
{
    alert('Hello has been displayed successfully');
}

Would there be a way to call test(); and then test_check() ONLY after test() has actually been completed ?

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Lukmo
  • 1,688
  • 5
  • 20
  • 31
  • This heavily depends on your usage of asynchronous tasks. If you don't have anything async, just call your functions one after the other. If you are having async operations they will probably supply you with a callback parameter. – m90 Sep 12 '12 at 08:53
  • This might help:: http://stackoverflow.com/questions/1937970/run-another-function-after-preceding-function-has-completed – Sudhir Bastakoti Sep 12 '12 at 08:54

3 Answers3

1

The function will return when it has completed, so you just call the next function after it:

test();
test_check();
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
1
var test = function()
{
    alert('Hello !');
    test_check(); /* call test_check() at the very end of test() */
}
alexbusu
  • 701
  • 4
  • 13
0

The following will work

test();
test_check();

test_check will execute after test finishes executing.

buydadip
  • 8,890
  • 22
  • 79
  • 154
Clyde Lobo
  • 9,126
  • 7
  • 34
  • 61
  • -1 That has nothing to do with the fact that Javascript is a single threaded language. The same applies to multi threaded languages also. – Guffa Sep 12 '12 at 11:12