JQuery Ajax POST XML结构/过滤器链

时间:2011-09-08 08:20:09

标签: javascript xml jquery

我想通过AJAX发布XML结构来获取过滤结果集。 web服务能够处理发布请求,但我的POST发生似乎有些问题。

$.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, ajaxOptions, 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>

由于

2 个答案:

答案 0 :(得分:30)

$.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);
    } 
}); 

看到这个答案可能有所帮助

jQuery ajax post to web service

答案 1 :(得分:-1)

也许最好在对象中设置值,并通过将ajax方法的dataType设置为'xml'将该对象作为xml发送到服务器。