JQuery Ajax POST XML结构/过滤器链

JQuery Ajax POST XML structure / Filter Chain

本文关键字:过滤器 结构 XML Ajax POST JQuery      更新时间:2023-09-26

我想通过AJAX发布一个XML结构来获得一个过滤的结果集。web服务能够处理帖子请求,但我的帖子似乎有问题。

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

谢谢

$.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到web service

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