Guys I fixed it...
I was not trying to access the data properly...
Instead of writing data[2] and expect to get the data from it,
I needed to ask for it explicitly: data[2].story.title.

This gave me the title...

Thx for your help guys..

On Aug 28, 10:07 pm, MorningZ <morni...@gmail.com> wrote:
> > The alert box that pops up diplays the following:
> >http://localhost:3000
> > [object Object]
>
> Are you expecting different?
>
> http://jsbin.com/oceni/edit
>
> alerting an evaluated JSON object will show you [object Object]
>
> If you want to see the JSON broken down into it's Key/Value pairs,
> Firefox + Firebug will show you that
>
> On Aug 28, 6:55 pm, lpdahito <lp.dah...@gmail.com> wrote:
>
>
>
> > Hi guys,
> > I have a problem retrieving data in JSON format using Ajax with
> > JQuery.
> > Here's the code I use:
>
> > /app/controllers/stories_controller.rb:
>
> > def index
> >     @stories = Story.all
> >     respond_to do |format|
> >       format.html # index.html.erb
> >       format.xml  { render :xml => @stories }
> >       format.json { render :json => @stories, :callback => params
> > [:callback] }
> >     end
> >   end
>
> > /app/views/layouts/application.html.erb
>
> > ...
> > <%= javascript_include_tag "jquery" %>
> > <script type="text/javascript">
> >     $(document).ready(function(){
> >         $.getJSON("/stories.json?callback=?", function(data){
> >             alert(data[2]);
> >         });
> >     });
> > </script>
> > ...
> > Here's the problem I have...
> > The alert box that pops up diplays the following:http://localhost:3000
> > [object Object]
> > What's worst is that Rails retreives my data and returns it in a
> > proper JSON format since when
> > I enterhttp://localhost:3000/stories.jsonIget the JSON file....
> > What's wrong with JQuery ??? I do exactly what they say on the
> > Website:http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
> > I need help please...
> > Thx...

Reply via email to