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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:27:51+00:00 2026-05-28T07:27:51+00:00

I use Backbone.js and jQuery 1.7 in my application and I have some problems

  • 0

I use Backbone.js and jQuery 1.7 in my application and I have some problems in building collection. In collection I have the method, which should return some object. I do “return” in $.ajax(…) success() function.

In this case i receive “undefined” instead of expected object. I understand, that the problem is in the “return” – it make success() function return some value. But I need getDomainZones() method do a return. How can I do it?

window.DmnList = Backbone.Collection.extend({
        model: DmnItem,
        localStorage: new Store("hosting.WhoIs"),
        destroyAll: function (options) {
            while (this.models.length > 0) {
                this.models[0].destroy(options);
            }
        },
        getDomainZones: function(){
            $.ajax({
                url: 'http://hosting/rest/getDomains',
                type: 'GET',
                dataType: 'json',
                cache: 'false',
                timeout: 5000,
                success: function(data) {
                    console.log(data);
                    return data;//problem here
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log("Error[getDomainZones]: " + textStatus);
                    console.log(jqXHR);
                },
            });
        }
});
  • 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-05-28T07:27:52+00:00Added an answer on May 28, 2026 at 7:27 am

    “Where I should place return statement”

    Nowhere. You can’t return the result of an asynchronous AJAX request.

    Any code that relies on the data, must be called inside the success callback.


    One possibility is to have your getDomainZones method receive a function that will be called when the response is received.

    getDomainZones: function( callback ){
        $.ajax({
            url: 'http://hosting/rest/getDomains',
            type: 'GET',
            dataType: 'json',
            cache: 'false',
            timeout: 5000,
    
       //   success: callback,  // alternative if there's no other work to do.
            success: function(data) {
                console.log(data);
    
                callback( data ); // invoke the function received
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log("Error[getDomainZones]: " + textStatus);
                console.log(jqXHR);
            },
        });
    }
    

    So then you’d pass a function to getDomainZones, and when the response is received, getDomainZones will invoke the function you passed, passing it the data.

    getDomainZones( function( d ) {
        // do something with the data
        console.log( d );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use backbone.js with jquery-template. So I have view: var CarpetView = Backbone.View.extend({ render:
I am currently develoing a Rails application which makes heavy use of some javascript
At my work we have an existing ASP.NET web application and are duplicating some
I know that I can use jQuery to access the view's element in backbone.js
I have been a user of jQuery (and some of its minor plugins) for
I'm building one page application using Backbone's router to modify browser history. I don't
Is it possible to use Backbone.js and jquery.datalink.js together to link a Backbone model
Backbone JS highly recommends you use jQuery. However, it doesn't do things very jQuery.
I am building a Backbone.js based interface on top of a custom SharePoint-based application
Is there any turotial to use both backbone js and Jquery together with rails

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.