概述
cs的代码
public string GetRoleManager(string name)
{
var rng = new Random();
List<RoleName> e = new List<RoleName>();
e.Add(new RoleName { roleName = "超级管理员", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "超级管理员", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "运营专员", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "市场主管", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "销售经理", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "技术主管", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "组长", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
e.Add(new RoleName { roleName = "员工", datetime = "2012-10-05 10:12:12", state = "已启用", operation = "停用 删除 编辑" });
return JsonConvert.SerializeObject(e);
}
js的代码
<script>
function JSONLength(obj) {
var size = 0, key;
for (var o in obj) {
size++;
}
return size;
};
var XHR = new XMLHttpRequest();
//使用变量赋值new个XHR请求
XHR.open("GET", "/RoleManager/GetRoleManager?name=12", true);
//open方法参数:请求方式|请求地址|是否异步(不写默认true)
XHR.responseType = "text";
XHR.send();
//返回类型:string|json|…
XHR.onreadystatechange = function () {
//准备状态改变触发
if (XHR.readyState == 4 && XHR.status == 200) {
var data = XHR.responseText;
var obj = JSON.parse(data); //由JSON字符串转换为JSON对象
var count = JSONLength(obj);
$("#table tr:not(:first)").html("");//清空表格内容
for (var i = 0; i < count; i++) {
var row = table.insertRow(table.rows.length);
if (i % 2 == 0) {
row.classList.add("evenrowcolor");
} else {
row.classList.add("oddrowcolor");
}
var c1 = row.insertCell(0);
//c1.parentElement.classList.add("ax_default");
//c1.parentElement.classList.add("table_cell");
c1.innerHTML = obj[i].roleName;
var c2 = row.insertCell(1);
c2.innerHTML = obj[i].datetime;
var c4 = row.insertCell(2);
c4.innerHTML = obj[i].state;
var c5 = row.insertCell(3);
var butt = document.createElement("button");
butt.style.height = "30";//高度
butt.style.width = "50";//宽度
butt.style.background = "#f30000";
butt.style.left = (60) + "px";
butt.innerHTML = "停用";
c5.appendChild(butt);
var butt1 = document.createElement("button");
butt1.style.height = "30";//高度
butt1.style.width = "50";//宽度
butt1.style.background = "#f30000";
butt1.style.left = (2 * 60) + "px";
butt1.innerHTML = "编辑";
c5.appendChild(butt1);
var butt2 = document.createElement("button");
butt2.style.height = "30";//高度
butt2.style.width = "50";//宽度
butt2.style.background = "#f30000";
butt2.style.left = (3 * 60) + "px";
butt2.innerHTML = "审核";
c5.appendChild(butt2);
}
}
};
</script>
最后
以上就是热情眼睛为你收集整理的js实现request的全部内容,希望文章能够帮你解决js实现request所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复