I want to Post an XML structure via AJAX to get a filtered result set. The webservice is able to handle post requests, but something seems to be wrong with my POSTing.
$.ajax({
url: ajaxurl,
data: {
inputxml: escape('<test></test>') <- how to post xml structure correctly?
},
type: 'POST',
contentType: "text/xml",
dataType: "text",
success : parse,
error : function (xhr, aj开发者_如何学编程axOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
XML:
<?xml version="1.0" encoding="UTF-8"?>
<f:filterChain
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:f="urn:foo">
<f:filter attributeId="number">
<f:rangeCondition conditionSign="INCLUSION" operator="BETWEEN">
<f:low>5</f:low>
<f:high>15</f:high>
</f:rangeCondition>
</f:filter>
</f:filterChain>
Thanks
$.ajax({
url: ajaxurl,
data: "<test></test>",
type: 'POST',
contentType: "text/xml",
dataType: "text",
success : parse,
error : function (xhr, ajaxOptions, thrownError){
console.log(xhr.status);
console.log(thrownError);
}
});
see this SO answer it may help
jQuery ajax post to web service
Maybe it's best to set your values in an object and send that object over to the server as xml by setting the dataType of the ajax method to 'xml'.
精彩评论