performs an async-POST ajax request
url | string | url to the server side |
params | string | optional, POST params |
callback | function | optional, a function to call after the response is loaded |
// simple data sending w/o post params
dhx.ajax.post("server.php?keep_alive=1");
// simple data sending with params
dhx.ajax.post("server.php", "keep_alive=1&version=std");
// data sending w/o params with callback
dhx.ajax.post("server.php", function(){
// your code here
});
// data sending with params and callback
dhx.ajax.post("server.php", "keep_alive=1&version=std", 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 POST request will be performed
var t = 1;
dhx.ajax.post("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.post("server.php", "action=get_nodes", 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.post("server.php", "action=get_nodes", function(r){
var t = dhx.s2j(r.xmlDoc.responseText); // convert response to json object
if (t != null && t.status == "ok") {
// response is ok
}
});
dhx.ajax.post("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
)
added in 4.0
Back to top