troubleshooting Question

javascript/html running too fast to get data from php scripts

Avatar of DCCoolBreeze
DCCoolBreeze asked on
JavaScriptHTMLPHPCOBOLjQuery
11 Comments1 Solution203 ViewsLast Modified:
I am working on an adobe captivate training course.  It uses javascript and is loaded via html with embedded javascript.  My company has developed jquery and javascript functions that call PHP scripts to pull employee information like employee number and name from the employee database. So that the employee does not have to type in their employee name and ID before a captivate course starts, I pull that information by calling the relevant javascript function that calls the appropriate php scripts to load several "global" javascript vaiables - these variables are displayed in the counsel "DOM" tab.  The problem I am running into is the html page continues to load before I can get the "global" variables.  For example.  I call a javascript function getEmpInfo() - which runs several php scripts to get lots of employee information - and then call alert(emp_id) and alert(emp_name); however, the html page is loaded so fast that the alert call runs before the php scripts finished - so I get nothing but blanks in the alerts.  I tried a javascript "sleep" but of course the html seems to ignore it and continues to load the page.  So interestingly enough.. sometimes the html gets the employee ID and name and runs fine, but other times gets nothing.  So is there a way I can be sure that my client side javascript gets the information it needs before starting the captivate training course - a call at the end of the html file.  I cannot do anything from the server side.

Oh.  the javascript calls for emp_id and emp_name do allow for a callback function.  So I added a callback function that contained an alert(emp_id).  It displayed a blank.  I also added a "sleep" javascript function call before the alert in the callback function to no avail.  I even set the "sleep" function to 10 seconds... did not work.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros