1
내가 있고, 내가 아래와 같이 Axios의와 샘플 침전물 Vuejs이 발행 어떤 답 :vuejs, 삭제
updateItem: function() {
var obj = {'name': this.name, 'dob': this.dob, 'gender': this.gender}
// console.log(obj)
var strngObj = qs.stringify(obj)
this.axios.put('http://localhost:3000/crud/update/', this.update_id,
strngObj, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
// emulateJSON: true // fix cannot post as form data and urlencoded
).then((resp) => {
if (resp.data.log === 'update success !') {
this.items.push(resp.data.data)
alert(resp.data.log)
}
console.log(resp.data) // check full object in browser console log
})
},
이 코드는 아래의 서버 측에게 있습니다
app.put('/crud/update/:UPid', (rqs, rsp, next) => {
rqs.header("Access-Control-Allow-Origin", "*");
rqs.header("Access-Control-Allow-Methods", "POST,PUT");
var obj = { "_id" : mongodb.ObjectID(rqs.params.UPid) };
var update = { $set : { name: rqs.body.name, dob: rqs.body.dob, gender:
rqs.body.gender} }; // $set is object
var cursor = db.collection('info').updateMany(obj,update, function(err, res)
{
if (err) throw err;
rsp.send({log: "update success !",data: obj});
console.log(rqs.body);
// console.log(update);
//db.close();
});
})
내가 검사를하고 크롬에서 디버그. 작성 및 읽기는 잘하지만 업데이트 (PUT 방식) 작업을 위해, 삭제 (DELETE) 전혀 작동하지 및 항상 오류 보여 아이디어
204 No Content
감사를!
데이터베이스에 문제가 있다고 생각합니다. 데이터베이스에 코드를 추가 할 수 있습니까? – imcvampire