How to use Ajax in TOUCH app?
There are 2 main ways (plus 1 additional) to use Ajax in your app:
The simplest way of Ajax using can be implemented in 5 forms:
dhx.ajax("some.php")
dhx.ajax("some.php", function(){ ... });
dhx.ajax("some.php", function(text, xml, XmlHttpRequest){ // text - full text of response // xml - response parsed as xml , if applicable // XmlHttpRequest - loader object //... });
dhx.ajax("some.php", function(text, xml, XmlHttpRequest){ // this == master_object //... }, master_object);
dhx.ajax("some.php", { error:function(text, xml, XmlHttpRequest){ alert("error"); }, success:function(text, xml, XmlHttpRequest){ alert("success"); } }); // callback is presented as a combination of 'error' and 'success' functions
There are two ways that Ajax can access the server:
async
dhx.ajax().get("some.php"); dhx.ajax().post("some.php");
sync
XmlHttpRequest = dhx.ajax().sync().get("some.php"); XmlHttpRequest = dhx.ajax().sync().post("some.php");
extra params
dhx.ajax().get("some.php","a=1"); //GET: some.php?a=1 dhx.ajax().post("some.php","a=2"); //GET: some.php; POST: a=2;
dhx.ajax().get("some.php",{ a:1 }); //GET: some.php?a=1 dhx.ajax().post("some.php",{ a:2 }); //GET: some.php; POST: a=2;
callback
dhx.ajax().get("some.php","", function(text, xml, XmlHttpRequest){ //.. }); dhx.ajax().post("some.php","", function(text, xml, XmlHttpRequest){ //.. });
This way is not so useful as mentioned above, but you can use it as well.
dhx.ajax.get("some.php", [callback1, callback2]); dhx.ajax().get("some.php", "", [callback1, callback2]);
If the response from the server is not string, you can use the toObject method. The method returns the response as a string which you can use accordingly:
XML
dhx.ajax.get("some.php", function(text,xml){ var obj = dhx.DataDriver.xml.toObject(text,xml); });
JSON
dhx.ajax.get("some.php", function(text,xml){ var obj = dhx.DataDriver.json.toObject(text,xml); });
CSV
dhx.ajax.get("some.php", function(text,xml){ var obj = dhx.DataDriver.csv.toObject(text,xml); });
HTML
dhx.ajax.get("some.php", function(text,xml){ var obj = dhx.DataDriver.html.toObject(text,xml); });
JSArray
dhx.ajax.get("some.php", function(text,xml){ var obj = dhx.DataDriver.jsarray.toObject(text,xml); });