Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  61] [ 7]  / answers: 1 / hits: 34850  / 12 Years ago, sun, december 16, 2012, 12:00:00

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?


More From » jquery

 Answers
6

Something 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.


[#81391] Friday, December 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennifer

Total Points: 517
Total Questions: 110
Total Answers: 104

Location: New Caledonia
Member since Fri, Sep 11, 2020
4 Years ago
;