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

postSync

performs a sync-POST ajax request

object postSync(string url, [string params] );

Parameters

urlstringurl to the server side
paramsstringoptional, POST params

Returns

objectloader object

Example

// simple data sending w/o post params
var r = dhx.ajax.postSync("server.php?keep_alive=1");
 
// simple data sending with params
var r = dhx.ajax.postSync("server.php", "keep_alive=1&version=std");

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 POST request will be performed

var r = dhx.ajax.postSync("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.postSync("server.php", "action=get_nodes");
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"}
var r = dhx.ajax.postSync("server.php", "action=get_nodes");
var t = dhx.s2j(r.xmlDoc.responseText); // convert response to json object
if (t != null && t.status == "ok") {
    // response is ok
}
  • you can both get/post params
var r = dhx.ajax.postSync("server.php?get1=1&get2=2", "post3=3&post4=4");
print_r($_REQUEST);
// result
Array
(
    [get1] => 1
    [get2] => 2
    [post3] => 3
    [post4] => 4
)
 
print_r($_GET);
// result
Array
(
    [get1] => 1
    [get2] => 2
)
 
print_r($_POST);
// result
Array
(
    [post3] => 3
    [post4] => 4
)
Change log

added in 4.0

Back to top