Created
December 23, 2011 21:03
-
-
Save adamdilek/1515351 to your computer and use it in GitHub Desktop.
Jquery Example for University API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
function faculty(university_id){ | |
$.getJSON('http://pigon.ws/university/faculties?university_id='+university_id+'&callback=?', | |
function(data){ | |
$.each(data,function(i,item){ | |
$('#faculty').append("<option value="+item.id+">"+item.name+"</option>"); | |
}); | |
}); | |
} | |
function department(faculty_id){ | |
$.getJSON('http://pigon.ws/university/departments?faculty_id='+faculty_id+'&callback=?', | |
function(data){ | |
$.each(data,function(i,item){ | |
$('#department').append("<option>"+item.name+"</option>"); | |
}); | |
}); | |
} | |
$(document).ready(function(){ | |
$.getJSON('http://pigon.ws/university/list/?callback=?', | |
function(data){ | |
$.each(data, function(i,item){ | |
$('#university').append("<option value="+item.id+">"+item.name+"</option>"); | |
}); | |
}); | |
$("#university").change(function() { | |
$('#faculty').find('option').remove(); | |
faculty($('#university').val()); | |
}); | |
$("#faculty").change(function(){ | |
$('#department').find('option').remove(); | |
department($('#faculty').val()); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form> | |
Üniversite : <select id="university"></select><br> | |
Fakülte : <select id="faculty"></select><br> | |
Bölüm : <select id="department"></select> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment