Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:36:55+00:00 2026-06-13T16:36:55+00:00

I am trying to use backbones.js fetch to get json from a twitter search

  • 0

I am trying to use backbones.js fetch to get json from a twitter search

and my code below can someone tell me where I am going wrong?

(function($){

  var Item = Backbone.Model.extend();

  var List = Backbone.Collection.extend({
    model: Item,
    url:"http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed"
  });    

  var ListView = Backbone.View.extend({    
    el: $('#test'),
    events: {
      'click button#add': 'getPost'
    },
    initialize: function(){
      _.bindAll(this, 'render', 'getPost');
      this.collection = new List();
      this.render(); 
    },
    render: function(){
      var self = this;      
      $(this.el).append("<button id='add'>get</button>");
    },
    getPost: function(){
      console.log(this.collection.fetch());
    }

  });

  // **listView instance**: Instantiate main app view.
  var listView = new ListView();      
})(jQuery);​

I am just getting started with backbone and I just want to console.log the json

you can see my example here. jsfiddle.net/YnJ9q/2/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:36:56+00:00Added an answer on June 13, 2026 at 4:36 pm

    There are two issues above:

    Firstly, you need to add a success/fail callback to the fetch method in order for you to have the fetched JSON logged to the console.

    getPost: function(){
        var that = this;
        this.collection.fetch(
        {
            success: function () {
                 console.log(that.collection.toJSON());
            },
            error: function() {
                 console.log('Failed to fetch!');
            }
       });
    }
    

    Another problem is the issue of “same-origin-policy’. You can find out how to resolve that by taking a look at this link.

    Update:
    I modified your code and included the updated sync method. It now works! Take a look here!

    Basically, update your collection to include the parse and sync methods as below:

    var List = Backbone.Collection.extend({
        model: Item,
    
        url: "http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed",
    
        parse: function(response) {
            return response.results;
        },
    
        sync: function(method, model, options) {
            var that = this;
            var params = _.extend({
                type: 'GET',
                dataType: 'jsonp',
                url: that.url,
                processData: false
            }, options);
    
            return $.ajax(params);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying use gem tire to search in my application. I have tables
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I've been trying to use backbonejs and jqm together. I can render the main
I'm trying to use Backbone.js to in a JQuery Dialog. I've managed to get
I have some test code that i'm just trying to use to figure out
I am trying to get the default values to use under a method. It
I'm trying to write some absolutely barebones code where I can drag a plain
I am trying use the django ORM to get a list by year of
I'm using Backbone.js 0.9.2 from the Backbone-on-rails gem. I'm also trying to use the
I am trying to use the backbone architecture in my MVC application. I created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.