I can't seem to get JSON when it's from an external file. When I write it inline, it works fine. But when I created a file called test.json and copied the JSON in to it, I never get the contents.
Here's my HTML and JavaScript. I should note that both HTML and JSON files are within the same folder.
What am I doing wrong?
<!DOCTYPE html> <html> <head> <title>JSON Sandbox</title> </head> <body> <h2>JSON Sandbox</h2> <p id="demo"></p> <script type="text/javascript"> var text = $.getJSON({ dataType : "json", url : "test.json", data : data, success : window.alert("JSON Aquired.") }); var obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.name + "<br>" + obj.street + "<br>" + obj.phone; </script> </body> </html> Here's my test.json file
{ "name":"John Johnson", "street":"Oslo West 1", "phone":"111 1234567" }
*.jsfile inspite of*.json..