Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to override Backbone.sync so it adds the apikey and username at the end?
    text
    copied!<p>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.</p> <p>I am trying to remove a view and its model using backbone with the following code:</p> <pre><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"); }}); }, </code></pre> <p>After the function executes, the browser tries to do a GET request on the following URL:</p> <pre><code>:8000/api/v1/update/2/ </code></pre> <p>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?</p> <p>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:</p> <pre><code>if ( !resp &amp;&amp; ( 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 + "&amp;api_key=" + window.app.settings.credentials.api_key, success: dfd.resolve, error: dfd.reject, }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload