phpjavascriptfunctionxajax

Calling xajax/ javascript function at the same time


I would like to ask if there is any way to execute the same function at the same time.. see this..

function convert_points()
{
    show_loading();
    xajax_ConvertPoints();
    xajax_GetRegularGamingCards();  
}

when the xajax_ConvertPoints is called. a MILISECOND delay after the xajax_GetRegularGamingCards is called. i proved that because of the logs that i put in each function.. like this..

2013-02-07 17:13:53 || LAUNCHPAD42 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||
2013-02-07 17:13:53 || LAUNCHPAD43 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||
2013-02-07 17:13:53 || LAUNCHPAD44 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||
2013-02-07 17:13:53 || LAUNCHPAD45 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||
2013-02-07 17:13:54 || LAUNCHPAD46 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||
2013-02-07 17:13:54 || LAUNCHPAD47 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 || 
2013-02-07 17:13:54 || LAUNCHPAD48 || TRANSACTION TYPE: CONVERT POINTS || SWCQAZ1 ||

Theres a difference in 2013-02-07 .54 and .53 (2013-02-07 17:13:53) MILISECONDS. is there any way to called it at the exact time?


Solution

  • It's impossible to have the same line of code guaranteed to be executed at the same millisecond in any kind of language. In JavaScript you can execute a functon without waiting for it's result and continue going to the other line of execution using setTimeout

    function convert_points(){
        setTimeout(show_loading,0);
        setTimeout(xajax_ConvertPoints,0);
        setTimeout(xajax_GetRegularGamingCards,0);  
    }