본문 바로가기

basic/Node.js

[Node.js] jQuery로 ajax 활용

function cartCheck() {

        var cnum = $('#cartNum').val();

        var uid = '<%=loginUser.userid%>';

        $.ajax({

            type: 'get',

            url: "/cartCheck?userid=" + uid,

            dataType: 'json',

            cache: false,

            success: function (res) {

                console.log(JSON.stringify(res));

                console.log(res.cartNum);

                $('#cartNum').text(res.cartNum);

            }, error: function (err) {

                alert('error: ' + err.status);

            }

        })

    }

 

///////////////////////////

 

exports.cartCheck = function (datareqres) {

    db.getConnection(dbconfig, (errcon=> {

        if (errthrow err;

        var sql = 'select count(userid) from cart where userid=:userid';

        con.execute(sqldata, (errresult=> {

            if (errthrow err;

            con.close((err=> {

                if (errthrow err;

                // console.dir(result);

                var n = result.rows.length;

                var obj = {};

                if (n > 0) {

                    // console.dir(result.rows);

                    obj.cartNum = result.rows;

                } else {

                    obj.cartNum = 0;

                }

                res.json(obj)

            })

        })

    })

}

'basic > Node.js' 카테고리의 다른 글

[Node.js] npx  (0) 2021.02.01
[몽고DB] 연결하기  (0) 2021.01.04
[Node.js] MongoDB 연결하기  (0) 2020.11.04
[Node.js] Ajax  (0) 2020.10.30
[Node.js] 나만의 Module만들기  (0) 2020.10.29