【发布时间】:2020-10-12 10:32:11
【问题描述】:
我在通过 ajax 调用向我的 Web 方法(C# Webforms)发送 XML 时遇到问题:
我已经使用 JSON 测试了 ajax 调用,并且能够将 JSON 发送到 Web 方法。
我的响应状态代码返回 200,但当我尝试发送 xml 时它没有触发 webmethod 上的调试器。
谁能告诉我我做错了什么?
JavaScript:
var test = '<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Dont forget me this weekend!</body></note>';
$.ajax({
type: "POST",
url: "/App/drawIOjs/draw.aspx/GetDocument",
data: { xml: test },
contentType: "text/xml; charset=utf-8",
dataType: "text",
success: function (msg) {
debugger;
alert(msg);
},
failure: function (msg) {
// failure code here
debugger;
alert(msg);
}
});
网络方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public static string GetDocument(string test )
{
string testing = test;
return "This string is from Code behind";
}
【问题讨论】:
标签: javascript c# ajax webforms webmethod