1. //1.如果返回的是JSONArray对象,那么用下面的方法打出来值
2. /*
3. $.getJSON("../servlet/JqueryServletForJson",{t:new Date()},function(data){
4. var len = $(data).length;
5. for(var i=0;i<len;i++){
6. $("#responseText").append($(data).get(i)+",");
7. }
8. });
9. */
10.
11. //2.如果返回的是JSONObject对象,无论是返回通过Map构造的还是JavaBean构造的
12. /*
13. $.getJSON("../servlet/JqueryServletForJson",{t:new Date()},function(data){
14. var name = data.name;
15. var age = data.age;
16. var address = data.address;
17. var phone = data.phone;
18. var mobile = data.mobile;
19.
20. $("#responseText").append("name: " + name +", age: " + age +
21. ", address: " + address+", phone: " + phone + ", mobile: " + mobile);
22. });
23. */
24.
25. //3.返回嵌套的json对象
26. $.getJSON("../servlet/JqueryServletForJson",{t:new Date()},function(data){
27. $("#responseText").append("<br/>用户信息<br/><hr/>");
28. for(var i=0;i<data.user.length;i++){
29. var user = data.user[i];
30. $("#responseText").append("name: " + user.name +", age: " + user.age +
31. ", address: " + user.address+", phone: " + user.phone + ", mobile: " + user.mobile + " <br/>");
32. }
33.
34. $("#responseText").append("<br/>经理信息<br/><hr/>");
35. for(var i=0;i<data.manager.length;i++){
36. var manager = data.manager[i];
37. $("#responseText").append("name: " + manager.name +", age: " + manager.age +
38. ", address: " + manager.address+", phone: " + manager.phone + ", mobile: " + manager.mobile + " <br/>");
39. }
40.
41. });
42.
43.
44. }
45.
46. -->
47. </script>
48. </head>
49. <body>
50. <input type="button" value="测试服务器回传json" onclick="getAjaxByJson()"/>
51. <div id="responseText"></div>
52. <div id="info"></div>
53. </bdoy>
54. </html>
posted on 2011-10-08 09:55
长春语林科技 阅读(1479)
评论(0) 编辑 收藏 所属分类:
jquery