• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Json error

 
tural ferhadov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have trouble with appending json elements to div...
my json is : {"childNodes":[{"categoryId":904,"categoryName":"wee"}]}
I want to append all names to div with each...

success: function(data) {

$.each(data.childNodes,function(i,c){
$("#childNodesDiv").html(c.categoryName);

});
}

But I get an errror stating that cannot read length property of undefined ..





Someone, please help me
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the built-in JavaScript debugger to set breakpoints and see what value is undefined. Once we know that, we can find out why it is undefined.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
childNodes has meaning in JavaScript, that is not the best name to use.
 
tural ferhadov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the name of variable , but again same mistake... "data.cNodesList undefined "
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that data is a JSON object? DId you debug it?

 
tural ferhadov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was not Json object, I didnot noticed that datatype was just an object, not json object. Already figured out. It was a silly mistake. I just did not write dataType:json . Thank you very much...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic