Hi dan,
Thanks for contacting Syncfusion support.
Query1: How do I change your POST query using a json object to a GET request transforming the json object to params in the url?
Currently we are processing the HTTP verbs type as “POST” in the DataManager. We can’t change this HTTP verbs type to another with in-built datamanger properties Could you please let us know for what purpose you are trying to port the ajax request functionality to Data manager?
Query 2: How do I transform the json object to a different format that my server is expecting?
To change the format in datamanager, we need to use custom adaptor. For example, if we pass the format as xml instead json, the processResponse has to be overridden to process the xml response from the server.
We have extended processResponse method of the ej.UrlAdaptor and in the extended method, the xml data from the server is converted into JSON array. We have performed simple Xml to Json conversion in the function “ConvertToJSON”, which will parse the simple xml document to json, in the below code:
<code>
<script>
//Creating the custom adaptor named xmlAdaptor by extending ejUrlAdaptor
var xmlAdaptor = new ej.UrlAdaptor().extend({
processResponse: function (data, ds, query, xhr, request, changes) {
return processXML(data.documentElement);
}
});
//Overriding default processResponse function
function processXML(ele) {
var json = ConvertToJSON(ele);
return { result: json["Order"], count: json["Count"] };
}
//Function to convert XML document to JSON object
function ConvertToJSON(ele) {
var json = {}, e, ch;
var addItem = function (parent, name, value) {
if (!parent[name])
parent[name] = value;
else {
if (parent[name].constructor != Array)
parent[name] = [parent[name]];
parent[name][parent[name].length] = value;
}
}
for (e = 0, ch = ele.childNodes; e < ch.length; e++) {
if (ch[e].nodeType == 1) {
if (ch[e].childNodes.length == 1 && ch[e].firstChild.nodeType == 3)
addItem(json, ch[e].nodeName, ch[e].firstChild.nodeValue);
else if (ch[e].childNodes.length != 0)
addItem(json, ch[e].nodeName, ConvertToJSON(ch[e]));
}
}
return json;
}
</script>
</code>
Now, we have to pass the custom adaptor in datamanager as shown below code:
<code>
<script>
var forgeryToken = $('[name=__RequestVerificationToken]').val();
var dataManager = ej.DataManager({
url: "GetXMLData",
adaptor: new xmlAdaptor(),
dataType: "xml",
headers: [{
token: forgeryToken
}]
});
</script>
</code>
We have prepared the sample based on your requirement and it is available under the following link:
We have showcased this in the below KB link:
Regards,
Kasithangam