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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:42:28+00:00 2026-06-03T15:42:28+00:00

I am using backbone-tastypie, but I am having the toughest time getting it to

  • 0

I am using backbone-tastypie, but I am having the toughest time getting it to work properly. In Tastypie, I am using ApiKeyAuthentication for my resources, so every ajax request, I need to append the apikey and username to the end of a request or send additional headers that add on the username and api key.

I am trying to remove a view and its model using backbone with the following code:

// Remove the goal update view from the DOM
removeItem: function() {
  this.model.destroy({wait: true, success: function() {
    console.log("success");
  }, error: function() {
    console.log("error");
  }});
},

After the function executes, the browser tries to do a GET request on the following URL:

:8000/api/v1/update/2/

It does not include the api_key or username at the end, and it has a trailing slash at the end of the url. I think it is trying to use Backbone.oldSync to do the GET request. How would I make it so the sync does include the username/api key at the end and removes the trailing slash?

In all of the other requests, I have made it so the api key and username is appended to the end of the http request by adding the following code to backbone-tastypie:

if ( !resp && ( xhr.status === 201 || xhr.status === 202 || xhr.status === 204 ) ) { // 201 CREATED, 202 ACCEPTED or 204 NO CONTENT; response null or empty.
  var location = xhr.getResponseHeader( 'Location' ) || model.id;
  return $.ajax( {
       url: location + "?" + "username=" + window.app.settings.credentials.username + "&api_key=" + window.app.settings.credentials.api_key,
       success: dfd.resolve,
       error: dfd.reject,
    });
}
  • 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-03T15:42:32+00:00Added an answer on June 3, 2026 at 3:42 pm

    Let’s explore the possibilities

    Using headers

    Backbone.sync still just uses jQuery ajax so you can override ajaxSend and use headers to send information along.

    $(document).ajaxSend(function(e, xhr, options) 
    {
        xhr.setRequestHeader("username", window.app.settings.credentials.username);
        xhr.setRequestHeader("api_key", window.app.settings.credentials.api_key);
    });
    

    Using Ajax Options

    If you need to send the information in just one or two locations, remember that the destroy, fetch, update and save methods are just shortcuts to the ajax caller. So you can add all jQuery ajax parameters to these methods as such:

    // Remove the goal update view from the DOM
    removeItem: function ()
    {
        this.model.destroy({
            wait: true,
            success: function () 
            {
                console.log("success");
            },
            error: function ()
            {
                console.log("error");
            },
            data: 
            {
                username: window.app.settings.credentials.username,
                api_key: window.app.settings.credentials.api_key
            }
        });
    }
    

    Overriding jQuery’s ajax method

    Depending on your needs, this might be the better implementation (note that this is no production code, you may need to modify this to fit your needs and test this before using it)

    (function ($) {
        var _ajax = $.ajax;
        $.extend(
        {
            ajax: function (options)
            {
                var data = options.data || {}; 
                data = _.defaults(data, {
                    username: window.app.settings.credentials.username,
                    api_key: window.app.settings.credentials.api_key
                });
                options.data = data;
                return _ajax.call(this, options);
            }
        });
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using backbone.js, and trying to fetch some json from twitter, but it
Have done some working samples using Backbone Router, but is there a way to
I'm using backbone for the first time while re-designing a major feature of an
I am using backbone validate function but it gives this error again Uncaught TypeError:
I'm using backbone.js and rails. When backbone.js saves a model for the first time
I am using Backbone.js to load 20 items at a time on the page,
im using backbone JS and im having troubles showing the data from the MODEL.
I'm building a backbone app using backbone-relational models (but that shouldn't matter for this
I'm using backbone.js and it works great. but the forms I'm creating as a
I'm using a combination of django-tastypie & backbone. I'm trying to do a DELETE

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.