[英]Sending XML with AJAX POST request to ASP.NET page?
I have an AJAX request like so: 我有这样的AJAX请求:
$.ajax({
type: "POST",
contentType: "text/xml",
dataType: "xml",
url: "send.aspx",
data:{xml:"<xml></xml>"}
}).done(function(reply){
console.log(reply);
});
I get no errors server side or client side, but when I try and write the output to the console server side, nothing comes up. 我没有在服务器端或客户端看到任何错误,但是当我尝试将输出写入控制台服务器端时,什么也没有发生。 I assume this is because ASP is seeing the XML string as an actual XML object or something of the sorts? 我认为这是因为ASP将XML字符串视为实际的XML对象还是某种对象?
Heres my ASP code: 这是我的ASP代码:
protected void Page_Load(object sender, EventArgs e){
System.Diagnostics.Debug.WriteLine(Request.Params["xml"]);
}
I ended up doing this: 我最终这样做:
protected void Page_Load(object sender, EventArgs e)
{
Page.Response.ContentType = "text/xml";
System.IO.StreamReader reader = new System.IO.StreamReader(Page.Request.InputStream);
String xml = reader.ReadToEnd();
String xmlData = HttpUtility.UrlDecode(xml);
System.Diagnostics.Debug.WriteLine(xmlData);
}
Take note that I used HttpUtility.UrlDecode() to decode my XML into a readable string. 请注意,我使用HttpUtility.UrlDecode()将XML解码为可读的字符串。 Thanks to Abin Jaik for the code. 感谢Abin Jaik提供的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.