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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:38:22+00:00 2026-06-10T00:38:22+00:00

In my Backbone View, I have two methods, one does a simple AJAX call,

  • 0

In my Backbone View, I have two methods, one does a simple AJAX call, and the other is the callback function I want to run. I want to call the AJAX method with the callback function as its parameter.

call_ajax_function: =>
  @get_stuff(@my_callback)

get_stuff: (callback_function) =>
  $.ajax
    url:'get_something'
    success: =>
      callback_function

my_callback: =>
  console.log "hello"

But I don’t think “my_callback” is getting called. Any ideas?

  • 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-10T00:38:24+00:00Added an answer on June 10, 2026 at 12:38 am

    You need to invoke your function, try changing

    get_stuff: (callback_function) =>
      $.ajax
        url:'get_something'
        success: =>
          callback_function
    

    to

    get_stuff: (callback_function) ->
      $.ajax
        url:'get_something'
        success: (data) => #success takes arguments, pass them thru
          callback_function(data)
    

    I think you don’t need to pass the argument into get_stuff like you are doing. So I think this should work

    get_stuff: ->
      $.ajax
        url:'get_something'
        success: (data) => 
          @callback_function(data)
    

    Plus, it should have the advantage that the context of the callback will be the instance, i.e. within the callback execution @ will be the correct instance.

    If you want to specify the callback method dynamically, AND you want to specify the scope on which that method executes, you need to use call like so

    get_stuff: (onSuccess)->
          $.ajax
            url:'get_something'
            success: (data) => 
              onSuccess.call @, data
    

    As a note, when defining methods on a class, I don’t thing => is buying you anything. Use -> for those methods. Use => when you want to look the context into an anonymous function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two backbone Views. One is the main view and the other is
I have two views, one represents a view of clients and the other is
I have a simple Backbone view which uses jQuery UI's buttons. For example I
I have a backbone view - which when called presents a form $('#add-offer').click(function() {
I have backbone view that binds an action to an element in the DOM.
I have a View (created using Backbone.View.extend) and a JSON object, I actually get
I have the view class FoursquareSearch.Views.Origin extends Backbone.View events: 'change [name=origin]': 'setOrigin' 'click [name=geolocate]'
I have a backbone view which load subview. When I load a subview, I
I have a Backbone View that has a Collection as its Model. If the
I have created a street view backbone view. The problem is that when shown,

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.