Skip to content

Instantly share code, notes, and snippets.

@ccbenavides
Last active November 27, 2017 18:03
Show Gist options
  • Save ccbenavides/98cc6db688e41af6e46aa05ac82f72a1 to your computer and use it in GitHub Desktop.
Save ccbenavides/98cc6db688e41af6e46aa05ac82f72a1 to your computer and use it in GitHub Desktop.
<script>
$('#albumSubmit').submit(function(e){
e.preventDefault();
var ambito = this;
console.log(this);
$.ajax({
url: '{{ route("admin.albums.store") }}',
method: 'post',
dataType: 'JSON',
data: {
'tipo' : $("#tipoMetodoAlbum").val(),
'identificador' : $("#identificadorAlbum").val(),
'name': $('#nombreAlbum').val(),
'description': $('#descripcionAlbum').val(),
'_token': '{{csrf_token()}}'
},
success: function(data){
if(data.name){
if(data.metodo == "put"){
$("#albumItem_" + data.id).html(`
<a href="#" class="album_enlace">
<i class="ti ti-folder"></i>
<p>${data.name}</p>
</a>`);
alert('Actualizado con éxito');
}
if(data.metodo == "post"){
$("#albumContent").append(`
<div class="col-sm-2 album_div" id="albumItem_${data.id}}">
<a href="#" class="album_enlace">
<i class="ti ti-folder" id="albumSeleccionado"></i>
<p id="albumSeleccionado">${data.name}</p>
</a>
</div>`);
alert('creado con éxito');
}
ambito.reset();
$("#modalAlbum").modal('hide');
}
},
error : function(data){
console.log(data);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment