这在折腾json遇到问题!

jiabin21 2010-10-30 04:46:32
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="/jquery-1.4.3.js"></script>
<script type="text/javascript" src="jquery.effects.core.js"></script>
<script type="text/javascript" src="/jquery.effects.explode.min.js"></script>
<script type="text/javascript" src="/json.js"></script>
<title>Untitled </title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 150px;
top: 172px;
background-color: #66FFFF;
}
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
</style>
<script type="text/javascript">
$(function() {
$("#apDiv1").show('explode',{},700);
});
$(document).ready(function(){
// 在这里写你的代码...
var sends='shuju';
$.ajax({
url:'http://localhost:8080/text.php',type:'post',dataType:'json',data:sends,success:update_page, error:function(){
alert("ajax error!") }

});

});
function update_page (json){
var arrs=JSON.parse(str);
var sts="";
addtr("jit");
tr_id = $("#jit>tbody>tr:last").attr("id");
tr_id++;
for (i = 0; i < arrs.length; i += 1){
sts="<tr>";
var arrst =arrs[i];
for(io=0;io<arrst.length; io += 1){
sts=sts+ "<td>"+arrst[io]+"</td>";
}
$('#jit').append(sts+"</tr>");
}

}

function addtr(id){
tr_id = $("#jit>tbody>tr:last").attr("id");
tr_id++;
//alert(tr_id);
str = "<tr id = '"+tr_id+"'><td >re1</td><td >re2</td><td>re3</td></tr>";
$('#'+id).append(str);
}

</script>

<link rel="stylesheet" type="text/css" href="my.css">
</head>
<body>
<div id="apDiv1">
<table width="200" border="1" id="jit">
<tr id="1">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr id="2">
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="button" name="bimn" id="bop" onclick="addtr('jit')">
</div>

</body>
</html>
老是说我 alert("ajax error!") !!! 
...全文
104 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
写成没一行都出来一个数组了!
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 cj205 的回复:]
引用 3 楼 jiabin21 的回复:

[["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"]][["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"],["2","hhhu","hhau","465496459"]]
我的格式有错吗?
json……
[/Quote]
劳烦你了!是我的循坏写错了!些习惯了!php也面了!
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
还有现在 不用 json.js了! 在这里花了很多时间!他回来就是一个数组了!
Mr-Jee 2010-10-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jiabin21 的回复:]

[["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"]][["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"],["2","hhhu","hhau","465496459"]]
我的格式有错吗?
[/Quote]json是键值对。你这格式。。。说数组包数组都不对。
建议你严格遵守JSON格式来做。
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
我知道了!放在循环里了!
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
$con=myconnect();
$qy=mysql_db_query("Devil","SELECT * FROM `myusr`",$con);
while( $row=mysql_fetch_row($qy))
{
$jiji[]=$row;
echo json_encode($jiji);
}
直接出来的!
famousboy 2010-10-30
  • 打赏
  • 举报
回复
你是要两个2维数组的结构?
Json一次不能包含2个对象,要返回2个数组的话,在外面包个大括号
{a1:[[...]], a2:[[...]]}
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
[["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"]][["1","jiabin","790a26695c7c9f38fa32d95bfa6b8e4p","2147483647"],["2","hhhu","hhau","465496459"]]
我的格式有错吗?
famousboy 2010-10-30
  • 打赏
  • 举报
回复
后台生成的json是什么样子的?
jiabin21 2010-10-30
  • 打赏
  • 举报
回复
patseererror 错误! 用php生成的json不合规定?

52,780

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧