The challenge I'm facing is loading names from an HTML file that contains JSON data. Oddly enough, the page appears blank/white without any error messages in the Firefox debugger.
Both test.html and persondb.html are located on the same server.
test.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8>
<title>JSON Example</title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<ul id="person-lista">
</ul>
<script>
$.ajax({
url: "http://www.mywebbpage.com/ajax/persondb.html", // not the realname
data: {
limit: 5,
name: 'ra'
},
success: function (response) {
var personArray = response.personer;
for(var i=0; i < personArray.length; i++) {
var person = personArray[i];
$('#person-lista').append('<li>' + person.fnamn + '</li>');
}
}
});
</script>
</body>
</html>
persondb.html
{
"personer": [{
"fnamn": "RACHELLE",
"enamn": "ZWIEFELHOFER",
"epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="186a797b707d74747d36626f717d7e7d7470777e7d6a586b77757d7e79737d7c777579717636766d">[email protected]</a>"
}, {
"fnamn": "RACQUEL",
"enamn": "JOH",
"epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65170406141000094b0f0a0d25160a080003040e00010a08040c0b4b0b10">[email protected]</a>"
}, {
"fnamn": "RAE",
"enamn": "BRAVARD",
"epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cab8abafe4a8b8abbcabb8ae8ab9a5a7afacaba1afaea5a7aba3a4e4a4bf">[email protected]</a>"
}, {
"fnamn": "RAFAEL",
"enamn": "SAGASTUME",
"epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4230232423272e6c312325233136372f2702312d2f2724232927262d2f232b2c6c2c37">[email protected]</a>"
}, {
"fnamn": "RAISA",
"enamn": "REINES",
"epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3d2e263c2e613d2a26212a3c0f3c20222a292e242a2b20222e262161213a">[email protected]</a>"
}]
}
Could it be that persondb.html isn't properly formatted? When viewed in a browser, it looks like this:
{ "personer": [{ "fnamn": "RACHELLE", "enamn": "ZWIEFELHOFER", "epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f78596949f929b9b92d98d809e9291929b9f98919285b784989a9291969c9293989a969e99d99982">[email protected]</a>" }, { "fnamn": "RACQUEL", "enamn": "JOH", "epost": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9dbc8cad8dcccc587c3c6c1e9dac6c4cccfc8c2cccdc6c4c8c0c787c7dc">[email protected]</a>" }, { "fnamn": "RAE", "enamn":...
Or possibly there's an issue with the "same origin policy"? Even though the files are on the same server (in the same folder).