这是后台方法返回的Json数据:
public ActionResult GetPoints()
{
string emp = Request.QueryString["fk_employee"];
string list = Request.QueryString["Alist"];
string month = Request.QueryString["Amonth"];
object obj = Models.Assessment.getPoints(emp,month,list);
return Json(obj, JsonRequestBehavior.AllowGet);
}
我在View接收后台方法传过来的数据
$(function () {
var list = $("#Alist").text();
var emp = $("#fk_employee").text();
var month = $("#Amonth").text();
$.getJSON("/Assessment/GetPoints?fk_employee=" + emp + "&&Amonth=" + month + "&&Alist=" + list, "", function (d) {
$("#ones").append(d.AssessID); //AssessID表中的主键ID
});
});
问题就是:为什么在页面显示的数据是undefined? 我用firebug查看方法已经获取了数据,就是无法显示成功?
在线等高手解惑!!!!!!
[{"AssessID":19,"ID":null,"fk_employee":"02004","empName":"刘沙沙","PointsID":2,"PointsName":"积极主动自觉完成本
职工作","Pweight":"工作态度","Pscore":8,"Amonth":"2015-08-04 00:00:00","Aself":0,"Amanager":0,"Ahr":0,"Ageneral"
:0,"Atotal":null,"Alist":null},{"AssessID":20,"ID":null,"fk_employee":"02004","empName":"刘沙沙","PointsID"
:3,"PointsName":"能有效沟通,主动协助他人完成相关工作","Pweight":"工作态度","Pscore":8,"Amonth":"2015-08-04 00:00:00","Aself"
:0,"Amanager":0,"Ahr":0,"Ageneral":0,"Atotal":null,"Alist":null},{"AssessID":21,"ID":null,"fk_employee"
:"02004","empName":"刘沙沙","PointsID":4,"PointsName":"需求分析:评估开发软件的性能和软硬件运行环境需求","Pweight":"工作业绩","Pscore"
:8,"Amonth":"2015-08-04 00:00:00","Aself":0,"Amanager":0,"Ahr":0,"Ageneral":0,"Atotal":null,"Alist":null
},{"AssessID":22,"ID":null,"fk_employee":"02004","empName":"刘沙沙","PointsID":5,"PointsName":"项目设计:概要设
计和详细设计","Pweight":"工作业绩","Pscore":5,"Amonth":"2015-08-04 00:00:00","Aself":0,"Amanager":0,"Ahr":0,"Ageneral"
:0,"Atotal":null,"Alist":null}]
看看是不是字母拼错了?
查看过了,没有错误
@玩世不恭的雷寅: 我去,你那返回的是数组吧?
@玩世不恭的雷寅: 如果不是undefined就怪了,既然是数组,你应该遍历才对。。。
@顾晓北: 奥,,,,,对对对对,我忘了这茬儿了,感谢朋友的提醒,现已经解决,谢谢!!!
看响应报文确定返回到前端的值是否正确
查看过了,没问题
改为 $("#ones").append(d) ,会显示什么结果?
还是undefined
@玩世不恭的雷寅: 将$.getJSON第2个参数由 "" 改为 {} 试试。
@dudu: 没有变化
@玩世不恭的雷寅:
建议改进一个代码。
js代码:
$(function () { var list = $("#Alist").text(); var emp = $("#fk_employee").text(); var month = $("#Amonth").text(); $.getJSON("/Assessment/GetPoints", { fk_employee:emp, Amonth:month, Alist:list}, function (d) { $("#ones").append(d.AssessID); } ); });
mvc代码:
public ActionResult GetPoints(string fk_employee, string alist, string amonth) { object obj = Models.Assessment.getPoints(fk_employee, amonth, alist); return Json(obj, JsonRequestBehavior.AllowGet); }
@dudu: 感谢你的建议。
@玩世不恭的雷寅: 我刚测试了,上面的代码可以正常拿到结果
@dudu: 也就是说如果将$("#ones").append(d.AssessID); 改为
$("#ones").append(“<input type='text' value="+d.AssessID+"”);
在页面显示的四个文本框里的数据就是 19 20 21 22