0 votes
1 view
in Web Technology by (15.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 });

        });

    }

};

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...