Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

I'm very newbie to nodejs.I'm practicing an Nodejs with express in MVC architecture with MySQL. All things are working fine, but I wonder why this application working POST request only once after server start.

This is my Controller

const IncData = require("../../models/Accounts_Models/Income_Model");

module.exports = {

    create_income_head(req,res){

        IncData.m_add_inc_head(req.con , req.body, function (err)

            {

                res.send(err);

            }

        )

    }

};

My Model

module.exports={

    m_add_inc_head: function (con,data,callback){

        con.query('CALL Create_Income_Head (?,?,?,?,?,?)',[data.income_category,data.description,1,0,'',''],callback);

    },

};

My Router

const express = require('express');

const router = express.Router();

const income = require("../../controllers/Accounts_Controllers/Income_Controller");

router.post("/add_income_head",income.create_income_head);

module.exports = router;

Someone please explain what went wrong in this code?

1 Answer

0 votes
by (25.1k points)

In your request you don't have successful response (so after request client side waits response but it's only for errors), try:

module.exports = {

    create_income_head(req,res) {

        IncData.m_add_inc_head(req.con , req.body, function (err) {

            if(err) {

              res.send(err);

            }

            // or just res.send('some message');

            // or res.status(201).end();

            res.status(201).json({ success: true });

        });

    }

};

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...