I've been displaying the ajax loading message when loading a php file (especially when there's a chance it won't run instantly).
I've been doing the following:
"showPageLoadingMsg" will start to display the ajax loading message and "hidePage~" will close it. The stuff in the middle loads what the php file returns into a div, then creates DOM contents for it with the trigger('create') function.
At first, I loaded all of my scripts in the header (even when the scripts weren't needed when the page was being loaded).
I found this website that partially explained how to load scripts when the page loads. However, Jquery Mobile needs to use the delegate function to load the script when a page is showing.
I copied the function from the website above:
Now, you need to add code to the top of the data-role="page" where you want the script to load:
Solution: Take the variable outside of the function.