jQuery does not return a JSON object to Firebug when JSON is generated by PHP
Posted
by Keyslinger
on Stack Overflow
See other posts from Stack Overflow
or by Keyslinger
Published on 2010-05-27T21:33:23Z
Indexed on
2010/05/27
21:51 UTC
Read the original article
Hit count: 436
The contents of test.json are:
{"foo": "The quick brown fox jumps over the lazy dog.","bar": "ABCDEFG","baz": [52, 97]}
When I use the following jQuery.ajax() call to process the static JSON inside test.json,
$.ajax({
url: 'test.json',
dataType: 'json',
data: '',
success: function(data) {
$('.result').html('<p>' + data.foo + '</p>' + '<p>' + data.baz[1] + '</p>');
}
});
I get a JSON object that I can browse in Firebug.
However, when using the same ajax call with the URL pointing instead to this php script:
<?php
$arrCoords = array('foo'=>'The quick brown fox jumps over the lazy dog.','bar'=>'ABCDEFG','baz'=>array(52,97));
echo json_encode($arrCoords);
?>
which prints this identical JSON object:
{"foo":"The quick brown fox jumps over the lazy dog.","bar":"ABCDEFG","baz":[52,97]}
I get the proper output in the browser but Firebug only reveals only HTML. There is no JSON tab present when I expand GET request in Firebug.
© Stack Overflow or respective owner