求個例子?
誰能給寫個Ajax 用json模擬 的例子!
19990000
2016-11-06 00:35:07
TA貢獻11條經驗 獲得超3個贊
<!DOCTYPE?html>
<html>
<head>
??<meta?charset="UTF-8">
??<title>jQuery?ajax?獲取本地json文件數據</title>
</head>
<body>
</body>
<script?src="./jquery.min.js"></script>
<script>
??$(function()?{
????$.get('./data.json',?function(res)?{
??????console.log(res);
??????//?獲取到數據后,顯示到頁面上
??????document.write(res.name);
????})
??})
</script>
</html>這是 html 內容,需要依賴jquery。下面是 data.json 內容
{
??"name":?"imooc",
??"url":?"http://www.xianlaiwan.cn/"
}重點是:要在服務器環境下打開!意味著你的瀏覽器地址不能是 file:// 開頭。
舉報