標籤: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