function start() {
$.ajax({
//要用post方式
type: "Post",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static string SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
//将结果转换成Json字符串
string result = serializer.Serialize(list);
return result;
}[WebMethod]
public static string SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
//将结果转换成Json字符串
string result = serializer.Serialize(list);
return result;
}
14 个解决方案
#1
先打个断点看下后台输出的result是什么,如果输出结果没问题的,那就试试把dataType改成json格式
#2
result输出的是表的字段和值,把dataType改成json格式还是不行
#3
html--->text
试试
试试
#4
这个也不行
#5
result返回的值是:
#6
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
#8
不是MVC
#9
$.each(data.d, function (i, item) {
#10
报错
#11
$.each(data, function (i, item) {
这样前面加一个
data=eval(data);
#12
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
不是MVC
$.each(data, function (i, item) {
这样前面加一个
data=eval(data);
报错:缺少‘;’
#14
你可以在后台直接把table的字符串组合完成,然后发给前台显示就完事了嘛
#1
先打个断点看下后台输出的result是什么,如果输出结果没问题的,那就试试把dataType改成json格式
#2
先打个断点看下后台输出的result是什么,如果输出结果没问题的,那就试试把dataType改成json格式
result输出的是表的字段和值,把dataType改成json格式还是不行
#3
html--->text
试试
试试
#4
html--->text
试试
这个也不行
#5
result返回的值是:
#6
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
#7
#8
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
不是MVC
#9
$.each(data.d, function (i, item) {
#10
$.each(data.d, function (i, item) {
报错
#11
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
不是MVC
$.each(data, function (i, item) {
这样前面加一个
data=eval(data);
#12
前台代码:
function start() {
$.ajax({
//要用post方式
type: "get",
//方法所在页面和方法名
url: "Second.aspx/SelectAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
t = "<table>";
t += "<tr>";
t += "<td>员工编号</td><td>员工姓名</td><td>工作</td><td>上级编号</td><td>受雇日期</td><td>薪金</td><td>佣金</td><td>所属部门</td><tr>";
$.each(data, function (i, item) {
t += "<tr>";
t += "<td>" + item.EMPNO + "</td>";
t += "<td>" + item.ENAME + "</td>";
t += "<td>" + item.JOB + "</td>";
t += "<td>" + item.MGR + "</td>";
t += "<td>" + item.HIREDATE + "</td>";
t += "<td>" + item.SAL + "</td>";
t += "<td>" + item.COMM + "</td>";
t += "<td>" + item.DEPTNO + "</td>";
t += "</tr>";
});
t += "</table>";
$("#table").html(t);
},
error: function (err) {
alert(err);
}
});
}
后台代码:
[WebMethod]
public static JsonResult SelectAll()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
//接收查询结果
List<EMP> list = EMPManager.SelectAll();
return Json(list);
}
不是MVC
$.each(data, function (i, item) {
这样前面加一个
data=eval(data);
报错:缺少‘;’
#13
如何在jQuery或javascript处理接收到json数据。可以参考:
http://www.cnblogs.com/insus/p/3713459.html
http://www.cnblogs.com/insus/p/3713459.html
#14
你可以在后台直接把table的字符串组合完成,然后发给前台显示就完事了嘛