Skip to content

Instantly share code, notes, and snippets.

@adamdilek
Created December 29, 2011 00:48
Show Gist options
  • Save adamdilek/1530783 to your computer and use it in GitHub Desktop.
Save adamdilek/1530783 to your computer and use it in GitHub Desktop.
Jquery Example for Location API
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
function districts(city_id){
$.getJSON('http://pigon.ws/location/districts?city_id='+city_id+'&callback=?',
function(data){
$.each(data,function(i,item){
$('#districts').append("<option value="+item.id+">"+item.name+"</option>");
});
});
}
function regions(district_id){
$.getJSON('http://pigon.ws/location/regions?district_id='+district_id+'&callback=?',
function(data){
$.each(data,function(i,item){
$('#regions').append("<option value="+item.id+">"+item.name+"-"+item.postal_code+"</option>");
});
});
}
function streets(region_id){
$.getJSON('http://pigon.ws/location/streets?region_id='+region_id+'&callback=?',
function(data){
$.each(data,function(i,item){
$('#streets').append("<option>"+item.name+"</option>");
});
});
}
$(document).ready(function(){
$.getJSON('http://pigon.ws/location/cities/?callback=?',
function(data){
$.each(data, function(i,item){
$('#cities').append("<option value="+item.id+">"+item.name+"</option>");
});
});
$("#cities").change(function(){
$('#districts').find('option').remove();
districts($("#cities").val());
});
$("#districts").change(function(){
$('#regions').find('option').remove();
regions($('#districts').val());
});
$("#regions").change(function(){
$('#streets').find('option').remove();
streets($('#regions').val());
});
});
</script>
</head>
<body>
<form>
il : <select id="cities"></select><br>
ilçe : <select id="districts"></select><br>
semt : <select id="regions"></select><br>
mahalle : <select id="streets"></select>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment