Check documentation for the latest version 6.0 of dhtmlxSuite getSync DHTMLX Docs

getSync

performs a sync-GET ajax request

object getSync(string url);

Parameters

urlstringurl to the server side

Returns

objectloader object

Example

// simple data sending
var r = dhx.ajax.getSync("server.php?keep_alive=1");

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)

  • sync GET request will be performed

var r = dhx.ajax.getSync("server.php");
console.log(r.xmlDoc.responseText); // script will wait for response
  • 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>
var r = dhx.ajax.getSync("server.php");
var items = [];
var xml = r.xmlDoc.responseXML;
var nodes = xml.getElementsByTagName("items");
for (var q=0; q<nodes.length; q++) {
    items.push({
        name:   nodes[q].children[0].getAttribute("name"),
        value:  nodes[q].children[0].getAttribute("value")
    });
}
  • getting json from response
// assuming that the response is the following
{status: "ok", data: "value", data2: "value2"}
var r = dhx.ajax.getSync("server.php");
var t = 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