如何在JQuery中使用XML内容创建HTTP POST请求?
问题描述:
是否有可能做这样的事情?如何在JQuery中使用XML内容创建HTTP POST请求?
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); } });
我到目前为止doenst工作。 JQuery能传递键值对吗? 谢谢!
答
$.ajax({
type: "POST",
url: "",
data: { inputxml: escape('<test></test>')},
success: function(msg) { },
});
答
您不妨使用$.post()
。是的,因为这将是x-www-form-urlencoded
,您需要一个密钥才能使用该XML值。
$.post(URL, {data: xmlString}, function (response) {
alert(response);
});
+0
奇怪的是,它不可能只发布一个http-body。 – intA
答
要发布XML/HTML服务器,你必须escape它。
$.ajax({ url: URL,
type: "POST",
data: {inputxml: escape(xmlString_HasMeasures)},
success: function(response){ alert(response); }
});
如果复制/粘贴,从实际工作茜代码,那么你应该修复ontentType到CONTENTTYPE –
也被xmlString_HasMeasures应该是你已经声明要了XmlString什么? –
[如何使用POST方法和使用jquery ajax传递XML作为参数的可能的重复](http://*.com/questions/920066/how-to-pass-xml-as-parameter-using-post-method-和使用jQuery的ajax) –