Hi John,
Certainly interested in helping if possible.
John Robin Dove wrote:
The failure symptoms are extremely random. Sometimes there is no error message. This is probably the most common situation. When there are messages they are often different. They make no sense. "tbfunction_showRequest is not defined" is nonsense because it is defined in black and white! Have I ommitted something like a semi-colon? I doubt it very much I've checking all the code over and over for days but I agree it's still a possibility.
I'll explain how showRequest and showRequest2 work but honestly I think this is a red herring. I don't even think they are culprits, just victims in a overall loss of "execution power". Things that were possible until recently are no longer available. Probably the more complex a function is the more likely it is to feature in a failure.
Random errors are interesting in web applications. They almost always suggest problems with how things are loaded and used.
In this case, your statement about tbfunction_showRequest() tells me that the js file that contains the definition for this function is not fully loaded before the code which relies on it tries to execute it. That is why the error pops up . . . that is also why the error Is random—it all depends on how the timing affects availability of functions in the DOM (Document Object Model). These error messages are never bogus and indicate an underlying problem. Even the browser used for testing can affect how quickly things load and become available. The challenge for developers is to make sure everything that is used is available in every case and works in all supported browsers.
Now consider this scenario:
Suppose I use an external js file called "myAddons.js" and it contains a function called tbfunction_showRequest().
Consider that it gets loaded this way:
on load page
pgExtFiles( "../media/myAddons.js", "load", "", true, "", "", ""); discard return value;
execute script showRequest(); store return value in myVar;
end load page
In this example, the line to execute showRequest() will randomly fail to work. The reason, is because the myAddons.js may not have finished loaded and adding its functions to the DOM because an attempt to execute occurs.
To guarantee that it will work, you could add a media delay, but that will only cause the problem to occur less often but not necessarily disappear.
So this is NOT the best solution:
on load page
pgExtFiles( "../media/myAddons.js", "load", "", true, "", ""); discard return value;
Delay 100ms
execute script showRequest(); store return value in myVar;
end load page
Of course if the delay is really long like 2000ms then the errors may disappear completely, but this is an unnecessary use of the delay mechanism built into JavaScript. Plus, once you put the application on the web, it may still fail because of latency issues.
The best solution is to use the pgExtFiles() parameter called
notifyOnLoad which tells pgExtFiles() to send a user event to an object when all the resources in myAddons.js are load and ready. Then you would place the rest of your actions on the notifyOnLoad object's user event. Now the call to showRequest() will never fail in any browser.
on load page
pgExtFiles( "../media/myAddons.js", "load", "", true, "", "addonsObj"); discard return value;
end load page
on user event [value]
Comment: for "addonsObj"
execute script showRequest(); store return value in myVar;
end user event
While this example considers how things work with js files, the problem also occurs with XML files managed by the PowerPac as well. The XMLHttpRequest() function also has a notifyObject parameter built in to allow it to work asynchronously as recommended by W3C (Worldwide Web Consortium).
MY POINT:- A failing PowerPac function is never (or at least extremely rarely) random, and if it was causing an error, it will consistently appear at the same failing location in the code. The error can usually be diagnosed either by content or by location in the code.
- I think there is a load sequencing issue in your application at the front end that is causing resources to not be available to the code when it is being called. The solution may be to look at the front end and ensure resources are loaded before they are used.
- I'm certainly glad to explore the possibility of a PowerPac issue, but so far we haven't been able to isolate one. Just because something once worked and now it doesn't could even be a result of a new browser versions (Edge, Firefox, Chrome, etc.). Browsers have been developed to do more and more asynchronously which means multiple files are loading and executing at once during the launch of a web application. You can see this using the "Network" tab in the Chrome and Firefox developer tools. So what once worked without verifying that resources were available, may no longer work in a newer browser version.
If you are using XMLHttpRequest() to load XML files and some of this code is giving random issues, I may want to look at an XML file or two to see if I can spot if loading the XML is giving trouble. While PowerPac's XML Parser has come a long way, this is the main component that has undergone changes in the course of PowerPac v14.0. You can examine the load process of XML files into a ToolBook application by using Firefox's developer tools (F12) > click the DOM tab > scroll down to the variable [
pg_xml] and explore the content of each indice of this array. Each XML file loaded will occupy its own indice. REMEMBER: Just because this variable may look fine, it doesn't mean your code had access to it when it tried to execute something.
Lot's to digest here!