jQuery訪問json文件 ajax訪問json文件 ...
<!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>json</title> <script src="json.js"></script> <script src="js/jquery-3.0.0.min.js"></script> <link rel="stylesheet" href="css/Imwang.css"/> <script type="text/javascript"> /** jquery 訪問json文件; */ /*function load(){ $(document).ready(function() { $.getJSON("網址.json",function(data){ var show = $("#顯示內容"); var strHtml = "";//存儲數據的變數 show.empty();//清空內容 $.each(data,function(infoIndex){ strHtml += '<dt><A onclick="點擊鏈接()" HREF="' + this["href"] + '" LAST_CHARSET="UTF-8">' + this["name"] + "</A></dt>"; strHtml += "<dd>" + this["description"] + "</dd>"; strHtml += "<dd>" + this["訪問次數"] + "</dd>"; strHtml += "<br /><hr />"; }); show.html(strHtml);//顯示處理後的數據 }); }); }*/ /** ajax 訪問json文件 */ function load1(){ $(document).ready(function() { $.ajax({ //請求方式; type:"get", //json文件; url:"網址.json", //返回數據類型; dataType:"json", //回調方法; success:function(data){ var show = $("#顯示內容"); var strHtml = "";//存儲數據的變數 show.empty();//清空內容 $.each(data,function(infoIndex){ strHtml += '<dt><A onclick="點擊鏈接()" HREF="' + this["href"] + '" LAST_CHARSET="UTF-8">' + this["name"] + "</A></dt>"; strHtml += "<dd>" + this["description"] + "</dd>"; strHtml += "<dd>" + this["訪問次數"] + "</dd>"; strHtml += "<br /><hr />"; }); show.html(strHtml);//顯示處理後的數據 } }); }); } </script> </head> <body onload="load1()"> <div id="divframe"> <div id="顯示內容"></div> </div> </body> </html>