0
votes

I am working on a backbone project where my js file is with save function that maps to a model.

this.model.save({
              success:function(){

},
attrs : attrs,
.
.
.
.

})

In the backbone model in the sync function i got

 sync:function(method, model, options){

       if(method == 'update'){
            options.url = 'my url here';
            options.data = JSON.stringify(_.omit(this.attributes,['username','firstname']))
}

    }

If i check the network response the output (in chrome) is

{'password':'','lastname':''}:

Hope you could see the last semi-colon (after the curly closing brackets) coming along with that object sent.

I tested the response with postman without the : and its working fine. So i concluded that semi-colon is added additional to the data on which my PUT request is rejected.

How can i over-come this?

1

1 Answers

0
votes

This looks fine:

var a = {'username': 'username', 'password': 'password', 'firstname': 'firstname', 'lastname': 'lastname'}
JSON.stringify(_.omit(a,['username','firstname']))
>>> "{"password":"password","lastname":"lastname"}"

Please paste more code. I would like to see the full sync call. Take a look at the implementation: http://backbonejs.org/docs/backbone.html#section-169