Я думаю, что это может быть проблема конфигурации, но я не могу понять, почему я могу сделать вызов из ajax, если contentType - "Json", но если я изменяю его на xml, он не вызывает этот webmethod. Может кто-то, пожалуйста, помогите.
Код ниже не работает.
В JavaScript
$.ajax({
type: "POST",
dataType: "xml",
contentType: "application/xml; charset=utf-8",
url: "Test.aspx/GenerateXML",
success: function (result) {
alert(result)
},
error: function (error, e1, e2) {
alert(error);
}
});
C # на странице aspx.cs
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml, UseHttpGet = false, XmlSerializeString = true)]
public static DataTable GenerateXML()
{
TestCalculator testCalculator = new TestCalculator();
DataTable dataTable = new DataTable();
dataTable = testCalculator.GetValue("Test");
return dataTable;
}
Рабочий код
В JavaScript
$.ajax({
type: "POST",
dataType: "Json",
contentType: "application/Json; charset=utf-8",
url: "Test.aspx/GenerateXML",
success: function (result) {
alert(result)
},
error: function (error, e1, e2) {
alert(error);
}
});
C # код
[WebMethod]
public static DataTable GenerateXML()
{
TestCalculator testCalculator = new TestCalculator();
DataTable dataTable = new DataTable();
dataTable = testCalculator.GetValue("Test");
return dataTable;
}