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 7782793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:39:06+00:00 2026-06-01T19:39:06+00:00

I’ve been trying to connect my backbone.js application to an existing Codeigniter API. I

  • 0

I’ve been trying to connect my backbone.js application to an existing Codeigniter API. I looked at the todos example on github and built up from there.
I’m overriding the findAll function, which is invoked on ‘read’ and am trying to get the pages and return them back to the fetch function:

findAll: function() {
console.log(‘synch – findAll’);

var url = "/folio/get/8";
var data = ''; 

var postmethod = 'GET';

$.ajax({
    url : url,
    type : postmethod,
    async: false,
    data: data,
    success: function(response) 
    {
                    console.debug("response",response);
        console.debug("response.pages", response["pages"]);
        return _.values(response["pages"]);
    }
});

}

The API returns something like this – output via the console.debug(“response”, response):

{
    "id": "8",
    "facebook_id": "123456789",
    "title": "title",
    "access_date": null,
    "rating_avg": "0",
    "pages": [
        {
            "id": "6",
            "picture1": {
                "id": "3",
                "tag": "1",
                "tip": "Crazy",
                "facebook_picture_id": "1239102391023"
            },
            "picture2": "28",
            "picture3": "29",
            "picture4": null,
            "picture5": null,
            "picture6": null,
            "caption1": "caption 1",
            "caption2": "caption 2",
            "sequence": "2",
            "folio": "8",
            "ts": "2012-04-10 15:13:23",
            "template": "#page-template-2"
        },
        {
            "id": "5",
            "picture1": "24",
            "picture2": "25",
            "picture3": "26",
            "picture4": null,
            "picture5": null,
            "picture6": null,
            "caption1": "caption 1",
            "caption2": "caption 2",
            "sequence": "4",
            "folio": "8",
            "ts": "2012-04-10 15:13:23",
            "template": "#page-template-2"
        }
    ]
}

but then console.debug(“response.pages”, response[“pages”]) prints out “undefined”. Why does it do that?

Thanks a lot in advance!

——————– edit ———————

Thanks for your answer. The tip that I can just do ajax calls from within the model is really helpful. The thing is that I am trying to get several pages into one PageList Collection:

$(function(){
  // Page Collection
  // ---------------

  var PageList = Backbone.Collection.extend({

    model: Page,
    localStorage: new Store("wickes-backbone"), // this to get hold of my overwritten localstorage file - it is not actually a localStorage

    nextOrder: function() {
      if (!this.length) return 1;
      return this.last().get('order') + 1;
    },

    comparator: function(page) {
      return page.get('order');
    }

  });

  window.Pages = new PageList;
});

so within the appview intitialize function I am calling

Pages.fetch();

which populates all the pages and updates the view. I’m not really sure how to do that within the model itself?

  • 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-01T19:39:08+00:00Added an answer on June 1, 2026 at 7:39 pm

    I think your problem is how you’re using the success function in the $.ajax():

    $.ajax({
        url : url,
        type : postmethod,
        async: false,
        data: data,
        success: function(response) 
        {
            console.debug("response",response);
            console.debug("response.pages", response["pages"]);
            return _.values(response["pages"]);
        }
    });
    

    If you return something from the success function on an AJAX call, it’s going straight into the bitbucket. That _.values() isn’t heading anywhere. What comes out of a $.ajax() call is a promise, that’s all. That promise can have .done(), .fail() etc. attached to it later, it can also be used with .when() and for other purposes. However, it has nothing to do with the success function it will call later. That’s equivalent to just a .done() function attached to that promise.

    My guess is that what you really want is for AJAX to finish and then manipulate the results and then set them on the model.

    In general though, trying to force Backbone to be synchronous is not how it’s meant to be used. Even if you don’t intend to use the Sync built into Backbone and skip the fetch, save, etc. it still happily accommodates being called like so (and note that the model will just update when it updates, just like you were doing a fetch):

    var myModel = Backbone.Model.extend({
      goGetSomeData : function () {
        var scope = this;
    
        $.ajax(....).done(
          function (results) {
            scope.set(results);
          }
        );
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.