英文:
Table not displaying data after making an AJAX request
问题
我正在尝试使用jQuery AJAX从数据库中检索我的数据。我无法弄清楚我的代码有什么问题。我认为我在代码的脚本部分犯了一些错误。任何帮助将不胜感激。
<table class="table">
  <thead>
    <tr>
      <th>
        @Html.DisplayNameFor(model => model.userName)
      </th>
      <th>
        @Html.DisplayNameFor(model => model.password)
      </th>
    </tr>
  </thead>
  <tbody id="AdminList">
    <tr id="loadingStatus" style="color:red">
    </tr>
  </tbody>
</table>
$("#loadingStatus").html("加载中...");
$.get("/Admins/GetAdminData", null, DataBind);
function DataBind(AdminList) {
  var setData = $("#AdminList");
  for (var i = 0; i < AdminList.length; i++) {
    var Data = "<tr class='row_" + AdminList[i].empid + "'>" +
      "<td>" + AdminList[i].username + "</td>" +
      "<td>" + AdminList[i].password + "</td>" +
      "<td>" + "<a href='#' class='btn btn-warning' onclick='EditRecord(" + AdminList[i].empid + ")'><span class='glyphicon glyphicon-edit'></span></a>" + "</td>" +
      "<td>" + "<a href='#' class='btn btn-danger' onclick='DeleteRecord(" + AdminList[i].empid + ")'><span class='glyphicon glyphicon-trash'></span></a>" + "</td>" +
      "</tr>";
    setData.append(Data);
    $("#LoadingStatus").html(" ");
  }
}
public JsonResult GetAdminData() // 需要修复
{
  List<Admin> ad = new List<Admin>();
  var dat = db.Admins.Select(x => new {
    empid = x.empId,
    username = x.userName,
    passWord = x.password
  }).ToList();
  // foreach(DataRow dr in)
  // {
  //   ad.Add(new Admin
  //   {
  //     userName =
  //   });
  // }
  return Json(dat, JsonRequestBehavior.AllowGet);
}
英文:
I'm trying to retrieve my data from a database using jQuery AJAX. I can't figure out what's wrong in my code. I think i did some mistake in the script section of the code. Any help would be most appreciated
<!-- language: lang-html -->
<table class="table">
  <thead>
    <tr>
      <th>
        @Html.DisplayNameFor(model => model.userName)
      </th>
      <th>
        @Html.DisplayNameFor(model => model.password)
      </th>
    </tr>
  </thead>
  <tbody id="AdminList">
    <tr id="loadingStatus" style="color:red">
    </tr>
  </tbody>
</table>
<!-- language: lang-js -->
$("#loadingStatus").html("Loading...");
$.get("/Admins/GetAdminData", null, DataBind);
function DataBind(AdminList) {
  var setData = $("#AdminList");
  for (var i = 0; i < AdminList.length; i++) {
    var Data = "<tr class='row_" + AdminList[i].empid + "'>" +
      "<td>" + AdminList[i].username + "</td>" +
      "<td>" + AdminList[i].password + "</td>" +
      "<td>" + "<a href='#' class='btn btn-warning' onclick='EditRecord(" + AdminList[i].empid + ")' ><span class='glyphicon glyphicon-edit'></span></a>" + "</td>" +
      "<td>" + "<a href='#' class='btn btn-danger' onclick='DeleteRecord(" + AdminList[i].empid + ")'><span class='glyphicon glyphicon-trash'></span></a>" + "</td>" +
      "</tr>";
    SetData.append(Data);
    $("#LoadingStatus").html(" ");
  }
}
<!-- language: lang-csharp -->
public JsonResult GetAdminData()//needs fixing
{
  List<Admin> ad = new List<Admin>();
  var dat = db.Admins.Select(x => new {
    empid = x.empId,
    username = x.userName,
    passWord = x.password
  }).ToList();
  //foreach(DataRow dr in)
  //{
  //  ad.Add(new Admin
  //  {
  //    userName =
  //  });
  //}
  return Json(dat, JsonRequestBehavior.AllowGet);
}
答案1
得分: 0
区分大小写的问题,我更改了密码 = x.password
英文:
case sensitive issue i changed
password = x.password
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论