Hey guys I've been having a problem loading json file. Like nothing happens when I click the button which should load it up. New to HTML so any help would be very appreciated. This is just the function not the whole file!
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/layout :: layout (~{::body},'hello')}">
<body style="background-color:green;">
<div class="container">
<h1 style="font-family:verdana;"><center>ANAME</center></h1>
<input type='text' value='Input directory' id = 'input' style='width:200px;margin:0 50%;position:relative;left:-100px;'><br></br>
<input type='submit' value='Get Data!' id='demo' onClick='myFunction()' style='height:50px;width:100px;margin:0 50%;position:relative;left:-50px;'>
<script>
function myFunction() {
//---my custom validation---
var inputField = document.getElementById("input");
if (inputField.value == "" || inputField.value == "Input directory") {
return;
}
//---Loading JSON---
$.ajax({
url: "test.json",
dataType: "json",
data: {},
success: function(data){
//---Do whatever with the loaded 'data' variable;
alert('go');
},
error:function(error){
alert('Invalid');
}
});
}
</script>
</div>
</body>
</html>