I'm pretty new to backbone and how it works and inherited a bunch of code but I can't solve this at all:
I have a user model:
var User = Backbone.Model.extend({
idAttribute: 'username',
defaults: {
username: "",
email: "",
roles : [],
password: ""
}
});
var Users = Backbone.Collection.extend({
model: User,
initialize: function(args, options) {
if (options && options.dialog) {
this.dialog = options.dialog;
}
},
parse: function(response) {
if (this.dialog) {
this.dialog.populate(response);
}
return response;
},
url: function() {
var segment = AdminUrl + "/users";
return segment;
}
});
Then elsewhere in my view I'm doing:
user.save({username: $newtarget.val()},null);
or user.save();
The PUT is fired to the correct url but every time its triggered it sends the data
Content-Type application/x-www-form-urlencoded; charset=UTF-8
but my Jersey endpoint accepts application/json
Everywhere I read people are struggling to put urlencoded data but my problem is the otherway around!
Parameters are being send as url params:
username=admin&email=&password=admin&roles%5B%5D=ROLE_USER&roles%5B%5D=ROLE_ADMIN&id=1
===EDIT===
If I force the content type and data:
user.save({}, {data: JSON.stringify(user.attributes),contentType: "application/json"});
The put works fine, which is bizarre.