如何将XML从c#返回到JQuery
我的程序从jquery中给了我一个错误。我不明白为什么。我在c#中工作,但在jquery中不工作如何将XML从c#返回到JQuery,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,我的程序从jquery中给了我一个错误。我不明白为什么。我在c#中工作,但在jquery中不工作 using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb))) { writer.Formatting = System.Xml.Formatting.Indented; ser.Serialize(writer, ct);
using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb)))
{
writer.Formatting = System.Xml.Formatting.Indented;
ser.Serialize(writer, ct);
XMLContent = sb.ToString();
}
return Content(XMLContent, System.Net.Mime.MediaTypeNames.Text.Xml);
f
当我替换
return Content(XMLContent, System.Net.Mime.MediaTypeNames.Text.Xml);
与
移除
dataType: "xml",
从jquery来看,一切都正常 一种可以大大简化和优化ajax的方法是使用JSON而不是XML (除非您真的希望结果是XML) 在ASP.NETMVC中,您可以让您的操作返回Json作为结果
return Json(new {
variableName: someData,
anotherVariableName: someMoreData
});
在您的Js中:
$.post(
'yourActionName',
optionalData,
function(d) {
alert(d.variableName);
alert(d.anotherVariableName);
}
);
再简单不过了:)在JQuery Ajax部分,req.statusText值返回OK。所以,我被它可能是什么难倒了
return Json(new {
variableName: someData,
anotherVariableName: someMoreData
});
$.post(
'yourActionName',
optionalData,
function(d) {
alert(d.variableName);
alert(d.anotherVariableName);
}
);