码迷,mamicode.com
首页 > Web开发 > 详细

GET JSON IN JQUERY

时间:2014-08-27 21:53:48      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   java   io   for   ar   

 1 大神绕道,装逼的绕道。希望那些初学者和我这样的代码基础薄弱的人有用。
 2  根据今天群里各位说的 一一测试 全部通过。
 3 
 4 html 代码
 5 
 6 <!doctype html>
 7 <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
 8 <html>
 9 <head>
10     <meta charset="utf-8">
11     <title>document</title>
12     <link href="../css/app.css" type="text/css" rel="stylesheet" />
13     <script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
14 </head>
15 <script>
16 
17     $(function(){
18 
19         $("#getjson").click(function(){
20             $.getJSON("/index/getJson", { key: "getjson"}, function(json){
21                 alert("JSON Data: " + json.a);
22             });
23         })
24         $(".json").click(function(){
25             //用传统的ajax 注意其实上面的getJson 就是这种传统ajax一个简写而已
26             $.ajax({
27                 cache: true,
28                 type: "POST",
29                 url: /index/getJson,
30                 //data:$(‘#comform‘).serialize(),
31                 async: false,
32                 error: function(request) {
33                     tipslog(" error!", tiperror, 2);
34                 },
35                 success: function(data) {
36                     /*$obj = $.parseJSON(data);
37                     alert($obj.a)  测试可用*/
38                     $obj = eval("("+data+")");//通过测试可用 这是为了转成
39                     alert($obj.a);
40                 }
41             });
42 
43         })
44     })
45 </script>
46 <body>
47 <h1>操他妈装B的人</h1>
48 <input type="button" id = "getjson" value = "getJson">
49 <input type = "button" id = "parsejson" class = "json" value ="parseJson" >
50 <input type = "button" id = "eval" class = "json" value = "eval">
51 </body>
52 </html>
53 
54 后台代码
55 public function getJsonAction(){
56          $arr_test_json = array(a => "abcd",b => "bcad",c => "cdas",d => "defg");
57          $json = json_encode($arr_test_json);
58          echo $json;
59 }
60 
61 上述代码为PHP代码,java的话也有对应的函数将数组转json 也可以直接拼一个json格式

 

GET JSON IN JQUERY

标签:style   blog   http   color   os   java   io   for   ar   

原文地址:http://www.cnblogs.com/bin-pureLife/p/3940411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!