我从ajax调用web方法,我想返回一个数组。我试过以下代码:
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "adminCopyCrystalReport.aspx/getAllDirectoryNames",
//data: JSON.stringify({
// //"dirLocation": $(this).children('.pathValue').text()
// "dirLocation": correctPath
//}),
dataType: "json",
success: function (data) {
alert('Success = ' + data.d);
},
error: function (result) {
alert("Error");
}
});
public static GetFolderDetails[] getAllDirectoryNames()
{
string paths = "~CrystalReportFiles/";
List<GetFolderDetails> details = new List<GetFolderDetails>();
foreach (var dirr in new DirectoryInfo(System.Web.Hosting.HostingEnvironment.MapPath(@paths)).GetDirectories())
{
//dir.Add(dirr.Name);
}
GetFolderDetails fd = new GetFolderDetails();
fd.fullFolder = "xxx";
fd.folderName = "ccc";
fd.urlPath = "eee";
return details.ToArray();
}
它会引发500内部服务器错误。如果我返回一个字符串,我得到输出
答案 0 :(得分:0)
尝试序列化数组(使用p
)并使用Newtonsoft
:
Response.Write()
答案 1 :(得分:0)
也许你正在低于移民
在Global.asax
文件内的Application_Start
方法评论中
//RouteConfig.RegisterRoutes(RouteTable.Routes);
确保EnablePageMethods
ScriptManager
<asp:ScriptManager runat="server" EnablePageMethods="true">