Super-duper javascript noob here. I'm trying to fetch public repos from GitHub, and add them to a dl. I know this won't work on every website due to cross-site scripting, but GitHub offers a JSON-P API. I'm fairly certain that I'm doing this mostly the right way (it works), but the append function looks ugly, and I'm not sure if the way I'm triggering the script is considered best practice.
gh-project.js:
function get_github_public_repos(username) {
var the_url = "https://api.github.com/users/" + username + "/repos"
$.ajax({
url: the_url,
dataType: 'jsonp',
type: 'get',
success: function(data) {
for(i = 0; i < data.data.length; i++){
var repo = data.data[i];
if (!repo.fork) {
$('#gh-projects').append("<dt><a href='" + repo.url +"' title='" + repo.name + "'>" + repo.name + "</a>" + "</dt>" +
"<dd class='project-description'>" + repo.description + "</dd>" );
}
}
}
});
}
projects.html:
<!-- snip -->
<dl class="project-list" id="gh-projects">
<!-- To be filled in by Javascript. Hooray! -->
</dl>
</section>
<script src="/js/gh-projects.js"></script>
<script>get_github_public_repos('gfontenot')</script>
<!-- end of file -->
Thanks for the pointers.