1

I have the following code in my page. I am expecting a series of json objects to get returned from the person_output.aspx page, which it does successfully. However, when it comes to outputting the content, I receive an error.

  $.getJSON("ajax/person_output.aspx", { 'uID': 1 }, function(data) {
            $.each(data.items, function(i, item) {
            $("<span/>").html(item.first_name).appendTo("#content");
                });
            });

ajax/person_output.aspx produces the following json (this is only for one record..)

{
    "l_id": "49",
    "u_id": "1",
    "first_name": "john",
    "last_name": "doe",
    "title" : "General Manager",
    "color" : "333"
}

firebug produces the following error;

G is undefined
init()()jquery-1....2.min.js (line 12)
(?)()()URLINX5 (line 99)
I()jquery-1....2.min.js (line 19)
F()()jquery-1....2.min.js (line 19)
[Break on this error] (function(){var l=this,g,y=l.jQuery,p=l.....each(function(){o.dequeue(this,E)})}});
2
  • The error appears to be with the variable G. Is that defined anywhere? Commented May 18, 2009 at 19:39
  • The variable "G" is a result of jquery being compressed. you should try running it with a development version of jQuery and see if the output makes more sense in that case. Commented May 18, 2009 at 19:59

2 Answers 2

2

There is a comma after the color property in your JSON result, does removing it help?

Sign up to request clarification or add additional context in comments.

3 Comments

Good catch. I was about to say the same thing. +1
nope actually there were more lines which I did not paste for keeping things simple.. in the original one there is no comma after the last line. I am editing the question now..
You say "this is only for one record",.. you're returning an array of these objects wrapped in [{square: "brackets"}] ?
0

I'm new to firebug but you need to figure out what is undefined here


$.getJSON("ajax/person_output.aspx", { 'uID': 1 }, function(data) {
            $.each(data.items, function(i, item) {
            $("").html(item.first_name).appendTo("#content");
                });
            });

It is either data, data.items, item, or item.first_name. If you are returning an array, don't you need to do do something like data.items[i], rather than item.first_name? The way you have it setup now, "item" is probably 0,1,2,3...n

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.