Check documentation for the latest version of dhtmlxSuite get DHTMLX Docs

get

performs an async-GET ajax request

void get(string url, [function callback] );
urlstringurl to the server side
callbackfunctionoptional, a function to call after the response is loaded

Example

// simple data sending
dhx.ajax.get("server.php?keep_alive=1");
 
// data sending with callback
dhx.ajax.get("server.php", function(){
    // your code here
});

Details
  • 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
  • getting xml from response, make sure server returns valid xml and the "content-type" header is set
// 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")
        });
    }
});
  • getting json from response
// 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
    }
});
Change log

added in 4.0

Back to top