I am trying to do a basic getJSON()
, but I believe I am getting no results.
Here is my HTML/js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Management Sheet</title>
<meta name="description" content=" ">
<meta name="keywords" content=" ">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON("config.json",function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
});
</script>
</head>
<body>
<section>
<button>Actually Click me</button>
</section>
<div>
</div>
</body>
</html>
and my json
{
'line1':'Mike B so cool',
'line2':'Type your namasd',
'line3':'763-345',
'num_rows':'15',
'num_cols':'3',
'bgColorPage':'#f08008',
'bgColorFilled':'#08f008',
'bgColorEmpty':'#6f00ff'
}
when I click my button, I get no errors, but my div is not appended with anything.
try with text();
$.getJSON("config.json",function(result){
$.each(result, function(i, field){
console.log();
$("div").text(field + " ");
});
});
Try
{
"line1": "MikeBsocool",
"line2": "Typeyournamasd",
"line3": "763-345",
"num_rows": "15",
"num_cols": "3",
"bgColorPage": "#f08008",
"bgColorFilled": "#08f008",
"bgColorEmpty": "#6f00ff"
}
use above json
object and see.
Your code is perfect there is nothing wrong in your code use above object in json and test it you are guaranteed to be success.
i tried your script and i don't why but if you change the single-quote for double-quote works:
{
"line1":"Mike B so cool",
"line2":"Type your namasd",
"line3":"763-345",
"num_rows":"15",
"num_cols":"3",
"bgColorPage":"#f08008",
"bgColorFilled":"#08f008",
"bgColorEmpty":"#6f00ff"
}