Skip to content

Instantly share code, notes, and snippets.

@afr-dt
Last active March 16, 2017 23:28
Show Gist options
  • Save afr-dt/abdf7bd8eba1cb2785d98cfd73bcbb16 to your computer and use it in GitHub Desktop.
Save afr-dt/abdf7bd8eba1cb2785d98cfd73bcbb16 to your computer and use it in GitHub Desktop.
/*
* Method ajax for canal and medio
*/
$('#hospital_id').change(function(){
var data = "";
var url = $(this).data('url');
var params = 'hospital_id=' + $('#hospital_id').val();
$.ajax({
type : "GET",
url : url,
data : params,
async : true,
success : function(data) {
console.log(data.room_options)
var medio = $('#medio');
medio.find('option')
.remove()
$.each(data.room_options, function(key, value) {
$('#medio')
.append($("<option/>")
.attr("value",key.room_options)
.text(value.name).val(value.id));
$('#medio').select2();
});
},
error : function() {
alert ('Ha ocurrido un error');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment