GET JSON IN JQUERY

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.