-2
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<select id="people"></select>
</body>
<script type="text/JavaScript">
$select = $('#people');
//request the JSON data and parse into the select element
$.ajax({
type:'POST',
url: './Person.JSON',
dataType:'JSON',
success:function(data){
//clear the current content of the select
$select.html('');
//iterate over the data and append a select option
$.each(data.person, function(key, val){
$select.append('<option id="' + val.id + '">' + val.name + '</option>');
})
},
error:function(){
//if there is an error append a 'none available' option
$select.html('<option id="-1">none available</option>');
}
});
</script>
</html>
喜從本地JSON文件中的數據無法使用jQuery來readed ajax.even 我試圖使用$ .getjson()一樣來加載從本地JSON文件中的數據,輸出不能加載。如何使用jQuery AJAX
請幫幫我。
這是我的Plunker
https://plnkr.co/edit/?p=preview
它是一個空的重擊器 – brk
你提到「本地json文件」。你是否試圖從用戶本地磁盤上的文件讀取?這是不可能的。 – ADyson
我想你應該看看這個@GOPAL http://api.jquery.com/jquery.getjson/ –