Skip to content

Instantly share code, notes, and snippets.

@meirabruno
Created June 23, 2015 20:05
Show Gist options
  • Select an option

  • Save meirabruno/02c5f609fbfe6dbaa9dc to your computer and use it in GitHub Desktop.

Select an option

Save meirabruno/02c5f609fbfe6dbaa9dc to your computer and use it in GitHub Desktop.
Exemplo de consumo CMS GVces com jquery - V2
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exemplo de consumo API V2 CMS GVces</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<script>
(function() {
var gvcesAPI = "http://gvces.com.br/api/v2/noticias";
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', "Token token=SECRET_TOKEN");
}
});
$.get(gvcesAPI, function(data) {
if(data.meta.type == 'list'){
data.categories.forEach(function(item){
$("<div><strong>" + item.title + "</strong><br><span>" + item.slug + "</span><br><span>" + item.resume + "</span></div><span><p>" + data.meta.pages + "</p>").appendTo( "body" );
});
}else{
$("<div><strong>" + data.post_preview.title + "</strong><br><span>" + data.post_preview.date_published_complet + "</span><br><span>" + data.post_preview.resume + "</span></div><span><br><p>" + data.post_preview.content + "</p>").appendTo( "body" );
}
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment