Pregunta

I am using Backbone and using XEditable for inline editing.

i am doing the following in the url part as one of the parameters to be passed to call for function editable of XEditable :

url: function(params) {
            console.log(params);
            console.log(here.model);
            var saveUrl = here.model.url;
            here.model.url += '/'+here.model.attributes._id; //setting required url for the request to be sent on the server
                var d = new $.Deferred;
                here.model.save( 
                  {field:params.value},
                  { patch: true }, 
                  { error: function() {
                    console.log("error");
                      d.reject('Server Error..!');
                    }
                  },
                  { success: function() {
                    console.log("done");
                    d.resolve();
                    }
                  }
                );
                return d.promise();
              }

But when i save the data on the server

i get the error :

POST http://10.0.1.6:3000/g/spec/5229d8fff4ae7a3803000020 404 (Not Found) on console and 

also : on the browser, the saving state of X editable never ends.. means X editable goes on a infinite loop to print some message.

My first question why data is not able to be saved on the server? I have correctly checked this url via POSTMAN chrome plugin.

2nd Question is : if somehow data is not able to be saved on database, as i am using deferred object and rejecting the promise in case of error, why X-editable is not showing the error "Server Error..!".

¿Fue útil?

Solución

You should just leave url empty and use the x-editable success-callback, if you want to use backbone's one model.save. Eg. in the view's render-method, you have to set update your model and trigger save (manually or by change-handler for the model)

this.$el.find("#my-field").editable({
    type        : 'text',
    name        : myFieldTitle,
    value       : myCurrentValue,
    pk          : this.model.get('id'),
    url         : '',
    success     : function(response, newValue) {
        self.model.set(field.name, newValue);
        self.model.save(field.name, newValue);
    }
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top