我正在尝试从骨干中的后端获取数据,虽然数据被返回到前端,但是成功函数根本没有执行,但是执行console.log()on done会发出从后端获取的所有数据。
var app = app || {};
app.url = '/usernotes/';
app.AboutModel = Backbone.Model.extend({
url: function() {
return app.url;
},
defaults: {
about: 'No',
editorNote: ''
},
set: function() {
localStorage.setItem('about', JSON.stringify(this.toJSON()));
}
});
app.AboutView = Backbone.View.extend({
el: '#aboutParent',
events: {
'click #yes': 'GetData',
'click #no': 'Default',
'click #custom': 'OpenEditor'
},
template: _.template($('#about').html()),
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template, this);
},
Default: function() {
this.model.set({
about: 'No'
});
},
GetData: function() {
this.model = new app.AboutModel({});
app.email = $('#data-user').text();
app.username = $('#data-username').text();
this.model.fetch({
data: {
email: app.email,
username: app.username
},
type: 'POST',
processData: true,
success: function(data) {
$('.summernote .note-editable').html(data.attributes.about);
},complete: function(xhr, textStatus) {
console.log(xhr);
},
error: function() {
$('.summernote .note-editable').html('');
}
});
}
});
这就是它在快递后端的外观
exports.find = function(req, res) {
if (req.body === null || req.body === undefined) {
res.send(null);
} else {
req.app.db.models.UserNotes.findOne({
email: req.body.email,
username: req.body.username
}, function(err, user) {
if (err) {
res.send({
"error": "The Email Does not exist in the database"
});
} else {
res.send(user);
}
});
}
};