Javascript 如何更新主干模型并将其发送到express后端
我想更新主干模型,以便设置主干模型的数据,然后在express后端进行更新,但到目前为止,我还没有成功。我已经检查了路由上的URL,它是正确的,但到目前为止它还没有被发送到后端 下面是代码的更新部分Javascript 如何更新主干模型并将其发送到express后端,javascript,backbone.js,express,Javascript,Backbone.js,Express,我想更新主干模型,以便设置主干模型的数据,然后在express后端进行更新,但到目前为止,我还没有成功。我已经检查了路由上的URL,它是正确的,但到目前为止它还没有被发送到后端 下面是代码的更新部分 update: function() { this.$('#noteParent .note-editable').prop('contenteditable', false); this.$('#aboutParent .note-editable').prop('contente
update: function() {
this.$('#noteParent .note-editable').prop('contenteditable', false);
this.$('#aboutParent .note-editable').prop('contenteditable', false);
this.$('#update').prop('disabled', true);
var notes = this.$('#noteParent .note-editable').html();
var about = this.$('#aboutParent .note-editable').html();
var username = $('#data-username').text();
app.url = "/update-usernotes";
this.model.set({
username: username,
email: app.email,
about: about,
editorNote: notes
});
}
set方法是更新模型的正确方法吗?另外,在this.model.set之前执行console.log(this.model)时,我会获得更新的模型,因此如何将更新发送到后端?set在本地更改模型,当您希望请求后端使用
保存
this.model.save({
username: username,
email: app.email,
about: about,
editorNote: notes
},{})
使用this.model.save进行数据库操作
更多
您能说得更具体一点吗,您想发送PUT请求还是只向后端发出请求?我想更新后端的数据请告诉我您想如何更新后端的数据,通过发送什么类型的请求(如POST或PUT)?您的回答有效,我使用了POST请求可能的感谢副本,有效。我想,我必须使用set方法