Skip to content

Instantly share code, notes, and snippets.

@kodamirmo
Created July 5, 2017 22:02
Show Gist options
  • Save kodamirmo/a274f08acc98154d3a83207cd1969922 to your computer and use it in GitHub Desktop.
Save kodamirmo/a274f08acc98154d3a83207cd1969922 to your computer and use it in GitHub Desktop.
var template = '<div><span> <%= nombre %> </span><p><%= descripcion %></p><h4><%= precio %></h4><img src="<%= imagen %>"/></div>';
var compiled = _.template(template);
function createExperience(data) {
return compiled(data);
}
var xhr = $.ajax({
url: "http://52.26.247.55:8080/EWS/web/kit",
method: "GET",
}).done(function(respuesta) {
var arregloExperiencias = respuesta.data;
arregloExperiencias.forEach(function(experiencia){
console.log( "Experiencia: ", experiencia );
var dataToUnderscore = {
nombre : experiencia.attributes.kit,
descripcion : experiencia.attributes.descripcion,
imagen : experiencia.attributes.imagen,
precio : '$' + experiencia.attributes.precio
};
var htmlElement = createExperience(dataToUnderscore);
$('#contenedor').append(htmlElement);
});
}).fail(function(jqXHR, textStatus) {
cosole.log( "error: ", textStatus );
}).always(function() {
console.log( "complete" );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment