In order to dynamically create buttons based on the contents of a text file during the onload event, I have written a JavaScript function. However, despite being able to read the file and using alert messages to verify the correctness of the variable 'button', the buttons are not being created at all.
function createButtons(){
$(document).ready(function() {
alert("1");
$.ajax({
url : 'http://localhost:8080/SSAD/type.txt',
dataType : "text",
success : function (filecontent) {
var lines=filecontent.split('\n');
$.each(lines, function() {
if (this!='') {
var button='<button type="button" class="btn btn-block btn-inverse active" data-toggle="button tooltip" title="Click this to enable/disable viewing of'+this+'" onclick="toggleVisibility('+"'"+this+"'"+')">'+this+'</button>';
$("#crisisButtons").append(button);
}
});
}
});
});
}
HTML:
<div class="crisisButtons"></div>
<script type="text/javascript">window.onload = createButtons();</script>