1

i can save a model on parse.com writing:

var persona=new Person({username:"filiberto",password:"filiberto"});

persona.save( {
success: function (persona) {
console.log("modello salvato nel db");
console.log(persona.url());

}
});

but if i first fetch a collection,get a specified model and update by save method doesn't work and error is:PUT https://api.parse.com/1/classes/_User/V742NGMTjA 400 (Bad Request)

Models.utenti = new Usercollection();
Models.utenti.fetch({async:false});

var current_user=Models.utenti.get(Parse.User.current().id);  
current_user.set_last_activity();
current_user.save();<----PUT https://api.parse.com/1/classes/_User/V742NGMTjA 400 (Bad   
Request) 

I've tried to update another class on parse.com and works. The class that i can't update is users,maybe a security reason?

Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96

1 Answers1

1

I'm unfamiliar with Parse, but according to their API (https://www.parse.com/docs/rest#users), a users request should be a POST not a PUT. Backbone uses PUT to update/sync models, whereas POST is used to create new models. The issue might be that Backbone is assuming that your model has already been saved and using the PUT method to update it.

Parse has a nice tutorial demonstrating the users API with Backbone (https://parse.com/tutorials/todo-app-with-javascript). You might also find this discussion addressing saving vs updating Backbone models helpful (Backbone model.save() is sending PUT instead of POST).

UPDATE: It appears that Parse requires Cross-Origin Resource Sharing (CORS) to modify existing users' data. In practice, this means adding additional information in the request header. See Parse's blog post in the comments below for more info and implementation details.

Community
  • 1
  • 1
Jay B. Martin
  • 499
  • 4
  • 11
  • To change the data on a user that already exists, send a PUT request to the user URL. By parse https://www.parse.com/docs/rest#users – Stefano Maglione Aug 08 '13 at 23:25
  • Are you modifying your own data? Otherwise, you'll need to "add a X-Parse-Session-Token header to the request with the session token provided by the signup or login method." – Jay B. Martin Aug 08 '13 at 23:34
  • I'm working on my own user...but i suppose it needs X-Parse-Session-Token.The problem is:how can I add this session token using backbone save method? – Stefano Maglione Aug 09 '13 at 10:49
  • This [blog post](http://webcache.googleusercontent.com/search?q=cache:_DBjdaqbPlAJ:blog.parse.com/2012/01/19/javascript-and-user-authentication-for-the-rest-api/+&cd=3&hl=en&ct=clnk&gl=us) by Parse shows how to add Cross-Origin Resource Sharing (CORS) using javascript. And this [tutorial](http://backbonetutorials.com/cross-domain-sessions/) shows how to implement it within Backbone's model framework. – Jay B. Martin Aug 09 '13 at 14:03