I currently have the following ajax call which runs successfully:
$.ajax({
url: "services/orders/<%=OrderServices.Action.BULK_SUPPLIER_DISCOUNT%>",
data: params,
complete: function(xhr) {
if (ajax.fullCheck(xhr, "delete your selected item")) {
unsavedChanges = false;
}
var xml = xhr.responseXML;
updateAutoTotalsFromXml(xml);
}
});
variable "xml" returns:
<Response><Totals><FixedCost>0</FixedCost><FixedPrice>0</FixedPrice><VarCost>70.4900</VarCost><VarPrice>224.87</VarPrice></Totals><Success/></Response>
however when i get to here, i get the error Uncaught TypeError: xml.find is not a function.
function updateAutoTotalsFromXml(xml) {
console.log(xml);
curFixedCost = parseFloat(xml.find("FixedCost").text());
curFixedPrice = parseFloat(xml.find("FixedPrice").text());
curVarCost = parseFloat(xml.find("VarCost").text());
curVarPrice = parseFloat(xml.find("VarPrice").text());
}
ideas?
According to jQuery.parseXML():
Parses a string into an XML document.
jQuery.parseXML uses the native parsing function of the browser to create a valid XML Document. This document can then be passed to jQuery to create a typical jQuery object that can be traversed and manipulated.
You can convert the xml to a jqueryObject and only after you can use the find function:
var xml = '<Response><Totals><FixedCost>0</FixedCost><FixedPrice>0</FixedPrice><VarCost>70.4900</VarCost><VarPrice>224.87</VarPrice></Totals><Success/></Response>';
function updateAutoTotalsFromXml(xml) {
console.log(xml);
var xmlDoc = $.parseXML(xml);
var jqObj = $(xmlDoc);
curFixedCost = parseFloat(jqObj.find("FixedCost").text());
curFixedPrice = parseFloat(jqObj.find("FixedPrice").text());
curVarCost = parseFloat(jqObj.find("VarCost").text());
curVarPrice = parseFloat(jqObj.find("VarPrice").text());
console.log('curFixedCost: ' + curFixedCost +
' curFixedPrice: ' + curFixedPrice +
' curVarCost: ' + curVarCost +
' curVarPrice: ' + curVarPrice)
}
updateAutoTotalsFromXml(xml);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div>