dhx.proxy is a DHTMLX component allowing you to send web requests via the proxy object. It defines a 'medium' data storage (cookie, session or local) that will keep the latest successful data files (further referred as 'the latest copy') and unsuccessful web requests.
dhx.proxy is an easy-to-use component. All you need to do is to instantiate it and specify the instance as the url parameter of the component(s) that will take data from the server.
var source = new dhx.proxy({ url: "./data.php", storage: dhx.storage.cookie }); mygrid = new dhtmlXGridObject('gridbox'); ... mygrid.load(source);
dhx.proxy can be initialized in the following way:
var source = new dhx.proxy({ url: "./data.php", storage: dhx.storage.session });
The constructor takes 2 parameters:
If for connecting to the server you use dataProcessor, you should specify the dhx.proxy instance in the constructor. After this, all web requests start to be passed to the server through proxy.
var source = new dhx.proxy({ url: "./data.php", storage: dhx.storage.cookie }); mygrid = new dhtmlXGridObject('gridbox'); ... mygrid.load(source); myDataProcessor = new dataProcessor(source); myDataProcessor.init(mygrid);
In case you don't use dataProcessor and 'write' the server-client logic manually, you will need these 2 methods:
The methods work like normal Ajax GET and POST requests.
var source = new dhx.proxy({ url: "./data.php", storage: dhx.storage.cookie }); mygrid = new dhtmlXGridObject('gridbox'); .... mygrid.load(source); var params = ["a=1", "b=2"]; // request parameters list source.post( params.join('&'), { success: function() { moveItem(id, $$('mylist'), $$('ready_list')); }, error: function() { moveItem(id, $$('mylist'), $$('proxy_list')); } });
To make it easy to learn the topic, you can go through step-by-step tutorial - Making apps work offline.
As you follow the tutorial, you will create a simple grid linked to db that continues to run and be updated even when the app doesn't have connection to Internet.