I get the above error on the jQuery v1.7.2 code when I try to use the $.each
method:
$.post('url_of_php_file.php',
$.param( {
}),
function(data){
$.each(data.articles, function(index, value){
.....
});
The request returns:
{"articles": [
{
"id":"11",
"date":"2012-12-19 15:52:06",
"title":"url_title",
"link":"url_link",
"available":"1"
},
..... *more rows like the above*
]}
Why do I get this error?
I get the above error on the jQuery v1.7.2 code when I try to use the $.each
method:
$.post('url_of_php_file.php',
$.param( {
}),
function(data){
$.each(data.articles, function(index, value){
.....
});
The request returns:
{"articles": [
{
"id":"11",
"date":"2012-12-19 15:52:06",
"title":"url_title",
"link":"url_link",
"available":"1"
},
..... *more rows like the above*
]}
Why do I get this error?
Share Improve this question edited Jan 20, 2016 at 0:48 Michał Perłakowski 92.5k30 gold badges163 silver badges186 bronze badges asked Dec 16, 2012 at 15:30 devmonsterdevmonster 1,7398 gold badges25 silver badges48 bronze badges 2- 1 Where do you get that error? – SLaks Commented Dec 16, 2012 at 15:33
- I get it on firebug add-on for Firefox. Seems that the 'a' is for the a in line 2 of jQuery v1.7.2: "(function(a,b)....." – devmonster Commented Dec 16, 2012 at 15:43
1 Answer
Reset to default 13Something you did caused an error inside jQuery. This is 99.9% of the time a bug in your code and not a bug in jQuery.
What helps is using the development version of jQuery. It is not minified, which means that it still has the full variable names instead of a
, b
, etc.
Did you send a:
header('Content-Type: application/json');
before the echo json_encode($data);
? That would triggers jQuery's JSON detection. Add a console.log(data);
before the $.each
to confirm the data looks like you'd expect.