UseAjax
UseAjax is a property of MPage objects that is used, along with UseAjaxUri, to use PHP code inside your mobile application, either the whole application or just some of its screens (MPage objects).
What it really does is to prepare your application to generate two twin applications: a mobile application, with only JavaScript code, and a web application with all the PHP code. You will then generate them, place your web application in a web server, and ship your mobile applications to your users.
Those two applications will then work in synchronization whenever your users perform an action requiring PHP code:
- Your mobile application will send its state to its web twin in your server. UseAjaxUri MPage property stores the URL of the web application, that is how your mobile application finds its web twin.
- Your web application will retrieve the data, perform any needed operation, and send back a new state to your mobile application.
- Your mobile application will retrieve and render that new state.
Before you choose to use UseAjax on any screen (MPage) of your application, you should take into account some facts:
- Your screen will be unusable on devices without a working Internet connection.
- Your screen will be unusable if the server hosting your web application is down.
- Your screen will be frozen, with a loading message box, while it retrieves each new status from the server. Depending on your user’s Internet connection, that can make the application feel slow or unresponsive.
UseAjax should only be chosen for those screens of your application that completely depend on PHP code to be functional. If PHP code is only used for optional features, you can develop a common mobile application, with JavaScript and its libraries, then develop a server-side PHP application, and whenever your mobile application has access to the Internet, use common AJAX calls to make those features work. That way, if your mobile application has no access to the Internet, you can just disable those features.
Run in a Web Browser
Tip: There is a video tutorial which covers how to run UseAjax applications in a web browser.
When you are working on a mobile application with screens using UseAjax, you should probably empty UseAjaxUri property. When empty, UseAjaxUri points to your local web server, that way your mobile and web twin applications will be the same.
If UseAjaxUri is already pointing to the location where the web twin will be hosted, whenever you run your application in a web browser to test it, your mobile twin running in your web browser will try to synchronize with whatever UseAjaxUri is pointing at, probably a previous version of your web application, or maybe an empty location. Anyway, it will probably cause your screens using UseAjax to misbehave.
It is once you are about to deploy your application that you have to set the final values of those UseAjaxUri properties.