performs an async-GET ajax request
url | string | url to the server side |
callback | function | optional, a function to call after the response is loaded |
// simple data sending
dhx.ajax.get("server.php?keep_alive=1");
// data sending with callback
dhx.ajax.get("server.php", function(){
// your code here
});
to prevent caching in some browsers an extra param like "dhxr0123456789" will be added
(to disable: dhx.ajax.cache=true, please check details here)
async GET request will be performed
var t = 1;
dhx.ajax.get("server.php", function(){
t = 2;
});
console.log(t); // still 1
// for php
header("Content-Type: text/xml");
<!-- assuming that the response is the following -->
<items>
<item name="first" value="a"/>
<item name="second" value="b"/>
</items>
dhx.ajax.get("server.php", function(r){
var items = [];
var xml = r.xmlDoc.responseXML;
var nodes = xml.getElementsByTagName("items");
for (var q=0; q<nodes.lengt; q++) {
items.push({
name: nodes[q].getAttribute("name"),
value: nodes[q].getAttribute("value")
});
}
});
// assuming that the response is the following
{status: "ok", data: "value", data2: "value2"}
dhx.ajax.get("server.php", function(r){
var t = window.dhx.s2j(r.xmlDoc.responseText); // convert response to json object
if (t != null && t.status == "ok") {
// response is ok
}
});
added in 4.0
Back to top