Hi I'm trying to change the ajax get key depend of the king of JSON file.
Here is my quick code :
$("#cbox2").click(function() {
var jsonlink = $('#jsonlink').val();
var jsonkey = $('#jsonkey').val();
$.ajax({
type: "GET",
url: jsonlink,
dataType: 'json',
cache: false,
success: function(data) {
data.forEach(function(post) {
$('#listacroche').append('<div class="row"><div class="col s5"><input name="foo" value="' + post.email + '" type="checkbox" id="checkgrp' + post.email + '" /><label for="checkgrp' + post.email + '">' + post.email + '</label></div></div>');
});
},
complete: function() {
console.log("List des groupes avec succès");
}
});
});
As you can see on the code the key is 'post.email' but if on another file it's 'post.userlog' or event 'post.mail' I would like to put the key in my #jsonkey input rather than changing my code.
Thanks