【发布时间】:2012-03-08 09:36:53
【问题描述】:
这是我第一次在 ASP.NET 中使用 AJAX,所以请允许我一些绳索。
我有一个简单的 AJAX 请求,我希望返回一个 JSON 字符串,但 ASP.NET 一直将 JSON 字符串格式化为 XML
这是我的代码
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetModels()
{
string response;
using (var context = new myDataModel())
{
var m = from model in context.ListModels select model;
var serializer = new JavaScriptSerializer();
response = serializer.Serialize(m);
}
return response;
}
这被调用但返回一个包含我的 JSON 字符串的 XML 节点真的很困惑
【问题讨论】: