<!doctype?html>
<html>
<head>
<meta?charset="UTF-8">
<title>jq的ajax查詢修改json</title>
<script?src="jquery-1.12.3.js"></script>
</head>
<body>
<h3>只輸入ID號為查詢,補全為添加新人信息</h3>
ID號:<input?type="text"><br>
姓名:<input?type="text"><br>
郵箱:<input?type="text"><br>
根據(jù)ID查詢的內(nèi)容:?<p?type="text"></p><br>
新添加的個人信息?<p?type="text"></p><br>
<button>查詢</button><br>
<button>添加</button>
</body>
<script>
$('document').ready(function(){
//?點擊獲取json文件的內(nèi)容
$(".chaxun").click(function(){
$.ajax({
url:?'jsonpage.json',
type:?'GET',
dataType:?'json',
})
.done(function(res)?{
var?objj='res';
/*?
var?obj=JSON.parse(objj);
使用這個JSON.pares()的時候報以下的錯:
“SyntaxError:?JSON.parse:?unexpected?character?at?line?1?column?1?of?the?JSON?data”并指向上面那行。
*/
//?下列發(fā)現(xiàn)只是展示了第一個數(shù)組:“root”,而沒有第二個數(shù)組;
var?obj=eval("("+objj+")");
console.log(obj);
console.log(obj[1].email);
})
});
/*?
問:
1.如何獲取json文件的指定對象或者是指定數(shù)組。
2.為什么JSON.pares()方法報錯。
3.為什么獲取的是整個json文件內(nèi)容,但是只展示第一個對應(yīng)的數(shù)組。
*/
})
</script>
</html>
=======================================下列是jsonpage.json的所有內(nèi)容========================================
{
"root":
[
{"uid":"0","name":"bill","email":"124548645@163.com"},
{"uid":"1","name":"tomz","email":"gooodaja1@qq.com"}
],
"hood":
[
{"uid":"0","name":"zip","email":"1freeque645@189.com"},
{"uid":"1","name":"hams","email":"486da451@gmail.com"}
],
}
2016-11-25
你好,服務(wù)器的話,是用WAMP軟件自帶的本地服務(wù)器。想請問一下,主要是服務(wù)器那個點的問題呢?我對服務(wù)器不是很內(nèi)行。
2016-11-24
目前來看是因為你的服務(wù)器的問題!