PHP和Javascript的JSON交互(处理一个二维数组)
PHP的JSON类库我使用的是Services_JSON
,没什么特别的优点,也没什么明显的缺点,对付用足矣。
建立文件data.php
:
<?php
include(
"JSON.php"
);
$data
= array(
array(
'name'
=>
mb_convert_encoding
(
'老王'
,
'UTF-8'
,
'GBK'
),
'age'
=>
'28'
),
array(
'name'
=>
mb_convert_encoding
(
'小黄'
,
'UTF-8'
,
'GBK'
),
'age'
=>
'27'
)
);
$json
= new
Services_JSON
();
echo
$json
->
encode
(
$data
)
;
?>
Javascript解析JSON我使用的是Jquery
,直接使用Javascript的eval则有个地方要注意:
var myObject = eval('(' + myJSONtext + ')');
具体可查看下面的参考链接。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>demo</title>
<script type="text/javascript" src="jquery-latest.pack.js"></script>
<script>
$(function(){
$.getJSON("data.php
", function(json){
for(var i = 0; i < json.length; i++)
{
alert("姓名:" + json[i].name);
alert("年龄:" + json[i].age);
}
});
});
</script>
</head>
<body>
</body>
</html>
参考资料:http://www.json.org/js.html
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
本文来自:http://forum.sysmu.com/thread-394-1-1.html
网通线路,部分文件下载比较慢,望谅解! 7 P+ q$ K. }0 ^$ l1 b
第一部分: html语言基础
ftp://edu:edu@ftp.hyperedu.cn:2003/视频教学1区/JavaScript张孝祥/01-01.rmvb
fftp://edu:edu@ftp.hyperedu.cn:2003/视频教学1区/JavaScript张孝祥/01-02.rm ......
大一点的框架都有这个东西。Prototype原来的继承机制非常弱,为了与mootools对抗也强化了这一方面。嘛,要用原型继承来模仿类继承,都基本存在一个克隆函数。把父类的原型属性复制到子类上去。理念的东西暂时这么多,动手实践一下最实际。我们设计一个数组类,拥有原生数组的能力与新扩展的能力。
var isNumber ......
本示例是要实现用javascript脚本读取xml文档,在xml文档中实现约束功能,test.html文件代码如下:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<script type="text/javascript">
......
HTML代码
<form action="" method="post">
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="1"/>
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="2"/>
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="3"/>
<input name="ID_D ......