Construct 2 has an AJAX object that will allow you to make a request to a target page in order to return the resultant data to AJAX.LastData where we can use the information collected.
In this tutorial I'm going to show you:
1. How to set up a simple interface that can form as the boilerplate for future tutorials.
2. How to set up a simple php file (we can also use a simple .txt file)
3. How to connect the AJAX object to make a call to our target page then return it to our HTML5 page.
If you are already familiar with Construct 2, you can skip step 1. The AJAX stuff is after building the interface.
Here's an example of what we're going to make:
Open full size image
It's located at:
If you click the image, it will do the following:
1. It will make a call to the target page. In our example the page is called ajaxexampleGET.php. It can really be any page that will render output to a browser window. For example, xml, txt or html.
2. When the call to the page is done, the information collected is stuffed into the AJAX.LastData object where we can then consume it in our game.
A critical part about getting data from a page is that there must be data to be collected. For example, if we go to:
You will notice that it just spits out the following information:
Open full size image That is basically what we're after and we want that information in our HTML5 page.
This is the same AJAX technique I used to create Cash Roll, a game I originally created for the iPhone and now also available as an HTML5 game.
You can check it out at: