My friend has this embarassing problem. He’s trying to get the most basic of JSON examples to work, and he’s having no luck whatsoever. When referencing JSON sources in the same folder it doesn’t work, but when getting Twitter or Flickr data it has no problem.
I could give you a dozen examples of ones that aren’t working, but here’s one:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>json demo: simple</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"> </script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script type="text/javascript">
$.getJSON('json.php', function(data) {
$('.result').html('<p>' + data.foo + '</p>' + '<p>' + data.baz[1] + '</p>');
});
</script>
</head>
<body>
<div id="result">
</div>
</body>
</html>
The output from json.php is:
{
"foo": "The quick brown fox jumps over the lazy dog.",
"bar": "ABCDEFG",
"baz": [52, 97]
}
This is an example taken off the web, and I’ve tried many more. Some don’t use PHP but a static text file, none of which work.
I’m embarassed to ask for help on something so basic… I mean he’s embarassed…
While I’ve not fixed this particular example, I’ve since got other and more complicated examples working. I think this one failed due to the api declaration, but I’m not concerned as my problem was getting ANY similar script working.
Apologies if anyone was looking at this.