wint100
asked on
AJAX Post build XML request body
Hi,
I have the following XML that I need to post to the server using an AJAX call:
My JS code is as follows but obviously I need to format the data element with the XML above:
I have the following XML that I need to post to the server using an AJAX call:
<?xml version='1.0' encoding="utf-8"?>
<Struct xmlns="http://bacnet.org/csml/1.2">
<Unsigned name="lifetime" value="1200"/>
<List name="values">
<Real name="1" value="33" via="/.bacnet/MainSite/5600/analog-value,1/present-value"/>
<Real name="2" value="44" via="/.bacnet/MainSite/5600/analog-value,2/present-value"/>
<Real name="3" value="66" via="/.bacnet/MainSite/5600/analog-value,3/present-value"/>
<Real name="4" value="88" via="/.bacnet/MainSite/5600/analog-value,4/present-value"/>
</List>
</Struct>
My JS code is as follows but obviously I need to format the data element with the XML above:
function createMulti() {
var url = "http://localhost/enteliweb/api/.multi";
var multiID;
$.ajax({
method: "POST",
url: url,
dataType: 'xml',
data:XML,
success: function(xml) {
//var $xml = $($.parseXML(xml));
$(xml).find('Real').each(function(idx, item) {
multiID = ($(item).attr("value"));
});
},
error: function(response, error) {
alert(response.status);
}
});
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.