简体   繁体   English

如何在JQuery中使用XML内容发出HTTP POST请求?

[英]How to make HTTP POST request with XML content in JQuery?

Is it possible to do something like this? 有可能做这样的事情吗?

var xmlString = 
            '<?xml version=1.0 encoding=UTF-8 standalone=yes ?>'+
            '<Requests>'+
              '<Request type=GetMeasures>'+
                '<Filter>'+
                  '<BBox top=52 bottom=51.3 left=7.3 right=7.7 />'+
                '</Filter>'+
              '</Request>'+
            '</Requests>';

$.ajax({ url: URL, type: "POST", ontentType: "text/xml", processData: false, data: xmlString_HasMeasures, success: function(response){ alert(response); } });

So far doenst work for me. 到目前为止,确实为我工作。 Can JQuery just pass key-value pairs? JQuery可以只传递键值对吗? Thanks! 谢谢!

You might as well use $.post() . 您最好使用$.post() And yes, because this will be x-www-form-urlencoded , you need a key to go with that XML value. 是的,因为这将是x-www-form-urlencoded ,所以您需要一个密钥来使用该XML值。

$.post(URL, {data: xmlString}, function (response) {
    alert(response);
});
$.ajax({ 
    type: "POST", 
    url: "", 
    data: { inputxml: escape('<test></test>')}, 
    success: function(msg) { }, 
});

To post xml/html to the server, you have to escape it. 要将xml / html发布到服务器,您必须对其进行转义

$.ajax({ url: URL, 
         type: "POST",
         data: {inputxml: escape(xmlString_HasMeasures)}, 
         success: function(response){ alert(response); } 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM