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 enter http://localhost:3000/stories.json I get the JSON file....
What's wrong with JQuery ??? I do exactly what they say on their
Website....
I need help please...
Thx...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---