1

I have a webservice returning jsonp format. here's the code:

$(document).ready(function(){               
       $.getJSON("http://api.tubeupdates.com/?method=get.status&lines=central,victoria&return=name&jsonp=?",
             function (result){
                  $.each(result.items, function(item){
                     $('body').append(item.response.lines[0].name);

             });
        }
     );

});

It works fine if I remove the loop but fails with the $.each loop. Any idea of what am I doing wrong?

Thanks

Mauro

1
  • What does the JSON data look like?! It kind of matters. Commented Nov 30, 2010 at 17:25

1 Answer 1

3

The response doesn't have an array on an items property, it looks like this:

{"response":{"lines":[{"name":"Central"},{"name":"Victoria"}]}}

It looks like you want to iterate the response.lines array, in which case you need to do this:

$.each(result.response.lines, function(i, item){
   $('body').append(item.name);
});

You can test it out here.

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

1 Comment

Thanks! didn't notice that 'response' wasn't an array!

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.