我有這個html代碼有兩個選擇標籤。我想用ajax填充我的'collegeselect'對應'departmentselect'。如何通過JSON文件使用JQUERY AJAX填充2選擇標記?
HTML代碼名「collegedepartment.html」
<html>
<title>College Life</title>
<body>
<select id="collegeselect" onchange=""myFunction()></select><br>
<select id="departmentselect"></select>
</body>
<script>
function myFunction()
{
}
</script>
</html>
有什麼辦法,你將填充選擇標籤ID =「collegeselect」的鍵值從JSON文件,然後將其在選擇標記id =「departmentselect」中加載其部門列表的值?我不知道該從哪裏開始,因爲我對這種編程語言很陌生,我正在從中學習。
這裏是JSON文件 JSON文件名'CollegeAndDepartment.js'
{
"College of CAS": ["Biology", "English", "LIACOM", "Library & Information Science", "Mass Communication", "Philosophy", "Political Science", "Psychology"],
"College of CICCT": ["Associate in Computer Technology", "B.S. Computer Science", "B.S. Information System", "B.S. Information Technology"],
"College of Commerce": ["Associate in Office Administration", "B.S. in Accountancy", "B.S. in Hotel and Restaurant Management", "B.S. Office Administration", "B.S. Tourism", "Business Administration", "Entrepreneurship", "Finance", "Human Resource Development", "Management", "Management Accounting", "Marketing"],
"College of Education": ["Bio-Chem", "Biology", "Computer Education", "English", "Filipino", "General Science", "Home Economics", "MAPE", "Mathematics", "Physical Education", "Science and Health", "Social Studies", "Values Education"],
"College of Engineering": ["B.S. Civil Engineering", "B.S. Computer Engineering", "B.S. Electrical Engineering", "B.S. Electronics & Communications Engineering", "B.S. Industrial Engineering", "B.S. Mechanical Engineering"],
"College of Law": ["Bachelor of Law"],
"College of Nursing": ["Associate in: Health Science Education", "B.S. Nursing"]
}
您不妨來看看點擊:http:/ /stackoverflow.com/questions/18064666/update-div-with-jquery-ajax-response-html – JonSG