简体   繁体   中英

MEAN Stack Angular 2 update(put) function is not running

I'm not sure why i'm having this weird error. I'm using route.put and selected PUT on my post man.

Here's my post man error: Image link-> https://ibb.co/dzvAKc

All of my musics on my mongoDB data: Image link-> https://ibb.co/d9TY5H

Routes:

const User = require('../models/user');
const Music = require('../models/music');
const jwt = require('jsonwebtoken');
const config = require('../config/database.js');
module.exports = (router) => {

Update function:

router.put('/updateMusic', (req, res) => {
    if (!req.body._id) {
        res.json({ success: false, message: 'No music id provided.'});
    }
    else { .. more authentications here }

return router;
};

Somehow it can't get pass that 1st if.

[UPDATE] :

Here's the img for the headers-> https://ibb.co/mGr9vH

It seems your have a typo here :

router.put('/updateMusic', (req, res) => {
    // if (!req.body._id) { <-- HERE _id, but it seems its id 
    if (!req.body.id)
        res.json({ success: false, message: 'No music id provided.'});
    }
    else { .. more authentications here }

return router;
};

Replace req.body._id with req.body.id Also - do you have app.use(bodyParser.urlencoded({ extended: true })); ? You are sending request with Content-Type application/x-www-form-urlencoded , so this line will parse this and assign data to body property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM