Created
December 12, 2013 16:45
-
-
Save dodopok/7931102 to your computer and use it in GitHub Desktop.
Categorias Mercado Livre
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
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script> | |
$(function(){ | |
$.get('https://api.mercadolibre.com/sites/MLB/categories', function(categories){ | |
for (var i in categories) { | |
$('#categories').append('<option value="'+categories[i].id+'">'+categories[i].name+'</option>'); | |
} | |
}); | |
}); | |
function getSubCategories(id){ | |
$('#subCategories option').remove(); | |
$('#subCategories').append('<option id="loading">Carregando...</option>'); | |
$.get('https://api.mercadolibre.com/categories/'+id, function(data){ | |
subCategories = data.children_categories; | |
for (var i in subCategories) { | |
$('#subCategories').append('<option value="'+subCategories[i].id+'">'+subCategories[i].name+'</option>'); | |
} | |
$('#subCategories #loading').remove(); | |
}); | |
} | |
</script> | |
<select id="categories" onChange="getSubCategories(this.value)"> | |
<option>Selecione a categoria</option> | |
</select> | |
<select id="subCategories"></select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The best of the world. I love you XD