gpt4 book ai didi

jquery - 通过 Jquery 获取 jsonString 为空

转载 作者:行者123 更新时间:2023-12-01 04:20:37 26 4
gpt4 key购买 nike

我正在使用 asp mvc,并且我正在像这样在程序的一部分中获取数据

 public List<IncidentPerAreaCount> getIncident()
{
int RondeboschCounter = 0;
int ClaremontCounter = 0;
int AthloneCounter = 0;
List<IncidentPerAreaCount> IncidentAreaCount = new List<IncidentPerAreaCount>();
IncidentPerAreaCount Rondebosch = new IncidentPerAreaCount();
IncidentPerAreaCount Claremont = new IncidentPerAreaCount();
IncidentPerAreaCount Athlone = new IncidentPerAreaCount();

List<Report> Reports = GetReports();
for (int i = 0; i < Reports.Count(); i++)
{
if (Reports.AsEnumerable().ElementAt(i).Area == "Rondebosch")
{
RondeboschCounter++;
}
else if (Reports.AsEnumerable().ElementAt(i).Area == "Claremont")
{
ClaremontCounter++;
}
else if (Reports.AsEnumerable().ElementAt(i).Area == "Athlone")
{
AthloneCounter++;
}

}
Rondebosch.AreaName = "Rondebosch";
Rondebosch.NumberOfIncidents = RondeboschCounter;
Claremont.AreaName = "Claremont";
Claremont.NumberOfIncidents = ClaremontCounter;
Athlone.AreaName = "Athlone";
Athlone.NumberOfIncidents = AthloneCounter;

IncidentAreaCount.Add(Rondebosch);
IncidentAreaCount.Add(Claremont);
IncidentAreaCount.Add(Athlone);

return IncidentAreaCount;
}

然后我尝试通过 Jquery 获取这个字符串

 var Reports = [];
$.ajax({
url: "Home/getIncident",
async: false,
dataType: 'json',
success: function (json) { Reports = json.whatever; }
});
alert(Reports);

但是,警报函数始终显示为空(即空文本框),而不是包含数据的 json 格式字符串。

请帮忙...

最佳答案

您将警报放在了错误的位置。

$.ajax({
url: "Home/getIncident",
async: false,
dataType: 'json',
success: function (json) {
Reports = json.whatever;
alert(Reports); // should be here.
}
});

阅读thisthis在进入代码之前。

关于jquery - 通过 Jquery 获取 jsonString 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10984137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com