0
var newUser = {
'username': $('#addUser fieldset input#inputUserName').val(),
'email': $('#addUser fieldset input#inputUserEmail').val(),
'fullname': $('#addUser fieldset input#inputUserFullname').val(),
'age': $('#addUser fieldset input#inputUserAge').val(),
'sex': $('input:radio[name="sex"]:checked').val(),
'profileimage':$('input[name="profileimage"]').val()
}
console.log($('input[name="sex"]').val());
// use AJAX to post object to adduser service
$.ajax({
type: 'POST',
data: newUser,
url: '/users/adduser',
dataType: 'JSON'
}).done(function (response) {...
後端JS(使用express.js和multer)
router.post('/adduser', upload.single('profileimage'), function (req, res) {
var db = req.db;
var collection = db.get('userlist');
var username = req.body.username;
var email = req.body.email;
var age = req.body.age;
var sex = req.body.sex;
var fullname = req.body.fullname;
if (req.file) {
var profileimage = req.file.filename;
} else {
var profileimage = 'noimage.jpg';
}
collection.insert({
"username": username,
"email": email,
"age": age,
"sex": sex,
"fullname": fullname,
"profileimage": profileimage
}, function (err, result)...
上面的代碼是不行。 我應該怎麼做將圖像信息插入到我的mongoDB數據庫中,並且可以顯示它。