SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Florida
    Posts
    58
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Jquery: run two functions at the same time

    I have two functions,
    import() calls and runs a script in the background, this script takes a while.
    updateStatus() gets the session variables set by the first script in order to keep status.

    The goal here is to run the script that takes a while and get the session vars at the same time to keep an updated "progress" as the bigscript runs. Both functions work I know that, the problem is that the update script is halted when the the import script is ran.

    The update script utilises "getJson" while I have tried using both "getJson" and "load" to run the import script. I have also switched the order in which the functions are called. (importStart is a global script var)

    Can any one tell me why? Or have any other suggestions?


    Code JavaScript:
    	$(document).ready(function(){
    		setInterval(function() {
        			updateStatus();
    		}, 3000);
    		if(importStart != 1){
    			import();
    			importStart = 1;
    		}
    	});

    **Update**

    import(); is not actually named import();

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    London
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    javascript isn't multithreaded, so you functions cannot run in the background.

    what does your import function do? can you make it do short bursts of work.. or if you are downloading data then do this asynchronously.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •