score:0
After a few hours I finally came up with a working solution. I started with the save command:
model.save({command:'approve'})
And then I overrode backbone's ajax command:
Backbone.ajax = function () {
var args = Array.prototype.slice.call(arguments, 0);
if (args[0].data) {
var model = JSON.parse(args[0].data);
var command = model.command;
if (command) {
args[0]['headers'] = { command: command};
}
}
return Backbone.$.ajax.apply(Backbone.$, args);
}
This code looks for the command value on the model (Backbone.save put it there), and pushes it to the headers. The next step will be to simply remove the command from the model before returning it.
score:1
You could tackle this a couple of different ways.
You could override Backbone syncwith your own implementation, as described here. Within your sync implementation, you would pull out certain params (like approve
), and jam them into the URL.
Or you could override the Model.url.
Related Query
- How does Dojo differ from Jquery with Backbone or with JavascriptMVC?
- ASP.NET MVC 2 Validating A Strongly Typed Model List With Data Annotations Exception When Using EnableClientValidation()
- Saving a data from html form to text file with jquery/javascript
- JSON Stringify for forms with same name params
- Replacing a sticky header with a second header when it reaches the currently stuck header
- Change URL params or remove some part of URL with jquery
- Saving Webpage With Javascript/jQuery Changes
- saving ajax response to array with Jquery
- Filtering backbone collection with multiple attributes
- backbonejs - same model with different attributes
- How can I process JSON data in JQuery, that's being returned with a header type of "text/html"?
- Set header id attribute from content with JavaScript
- Update Angular2 model after setting input value with jQuery
- Style header with `width: 100%` without using the `position` property
- Async post model and load response with MVC
- Backbone router doesn't work with requirejs
- Calculate a div's height with jQuery - minus header and footer
- Issue with Saving Dark Mode Preference (localStorage)
- Create smooth sticky header transition with CSS
- How to display data from code igniter model with AJAX request
- How to export a table with header to Excel with table2excel
- How to correctly associate a model with 2 different objects?(Rails 4)
- Wrapping <li> with <ul> until next header in JQuery
- ASP.NET MVC model binding with serialize
- Fixed header table inside a scrollable div with equal 'table head column width' and 'content column width'
- Getting Cloudinary direct uploads to work with a nested model and dynamically added upload fields
- Saving form state with javascript only on submit
- Saving application user interface options with rails
- canJS: load model with associations, but only save the "base" model
- Rails 3.2 ajax example with params in controller
- Image "Upload" to Canvas Object With JQuery - Not Saving on Server
- Codebehind (postback) vs Jquery with webservice (for saving data)
- Calling asp.net webmethod with params from jquery errors
- How to print javascript array with Model list
- Show and Hide element from Script and/or from Razor Model View with MVC
- account for fixed header with smooth scroll
- Full Calender Event array with MVC Model
- Fundamental Backbone issue with registering event handlers
- Export HTML Table to Excel with ID or class tags in the table header
- Resizable columns tables with fixed header
- MVC5 - How to pass fileupload along with model to controller using jquery ajax
- Calculate height with JQuery for sticky header
- RequireJS + Backbone + jQuery loaded through `script` interfering with jQuery loaded through RequireJS
- Post a serialized ASP.NET Model and a file with single Jquery Ajax call in ASP.NET MVC
- Backbone model CORS fetch not being sent
- jQuery, DataTables fixed header and column load time is slow with only 376 rows
- Saving javascript object into database with php script
- Ajax Post and Redirect with Model Value MVC4
- Right aligned div inside a header with a navbar breaks to other line
- Working with templates + jquery ui in backbone
More Query from same tag
- Passing php variable to modal twitter bootstrap not working
- Are image properties part of the DOM (jQuery - webkit inconsistency with other browsers)?
- Limit button clicks to once every 5 minutes
- for loop .. wait for AJAX request
- Is there a jQuery function to check wether a URL posts to another host?
- Google Maps API 3 is acting buggy
- jQuery If Statement - fiddle works, website doesn't
- innerHTML not working properly when used on a jQuery object
- onClick(), onMouseOver() and onMouseOut() with image
- creating margin with jQuery to position element below absolutely positioned element
- Remove specific numbers from array
- Check the type of draggable
- Generating Jquery Mobile site from Json
- Sending PHP Array to jQuery with $.post() and then looping through those values
- Count maximum nested list items JQuery, Javascript, HTML
- How to load a cross-domain page using JavaScript
- Show/Hide Div while using the same clickable link?
- Infinite scroll with no content
- Remove class from list item and add a class to a different list item using jquery
- dynamically change jquery tooltip
- Using JavaScript Ajax to retrieve content from another site
- Jquery text replace for specific characters on entire site
- Splitting a String at a certain point/character in jQuery
- quickly loading images in a webpage
- Extract custom html element attribute & content pasted in textarea using jQuery
- How can I achieve this image effect with jQuery?
- Asp.Net jQuery $.getJSON sometimes causes full page postback?
- jQuery how to select options by values?
- Javascript onclick function working only after asyncchronous request.?
- Change certain video source on click