先我们看演示代码
代码如下 | 复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ajax json test</title> <script language="javascript" src="./jquery-1.7.1.min.js" /></script> </head> <body style="font-family:Arial;line-height:150%"> |
当我们点击 获取所有用户信息在div的id=users中显示
Ajax返回的JSON字符串:
[{"userId":1,"userName":"Raysmond"},{"userId":2,"userName":"u96f7u5efau5764"},{"userId":3,"userName":"Rita"}]
解析出来的结果为:
userId = 1
userName = Raysmond
userId = 2
userName = 雷建坤
userId = 3
userName = Rita
上面代码大家可能看不懂,我们现在来详细介绍
代码部分
代码如下 | 复制代码 |
index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <script language="javascript" src="./jquery-1.7.1.min.js" /></script> </head> <body style="font-family:Arial;line-height:150%"> /** /** <?php //处理请求:以JSON格式返回所有用户信息 |