Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: Json is not defined [closed]

I am using express and Node.js. When I run the function below to get the value of an URL, Json.stringify(url) gives me the error.

ReferenceError: Json is not defined.

app.get("/id", function (req, res, next) {
    var id = req.param("id");
    connection.query('SELECT `url` FROM dynamic_url where id =' + req.param("id"), function (error, rows, fields) {
        if (err) {
            return next(err);
        }
        var url;
        if (rows.length === 0) {
            url = 'URL not available in database'
        } else {
            url = rows[0].url;
        }
        var i = Json.stringify(url);
        res.redirect(i);
    });
});
like image 987
user3013170 Avatar asked Nov 21 '13 05:11

user3013170


2 Answers

You have capitalization error on your JSON variable name. You need to use -

JSON.stringify(url)

not -

Json.stringify(url)

See the docs.

like image 131
MD Sayem Ahmed Avatar answered Sep 20 '22 04:09

MD Sayem Ahmed


Its not Json its JSON :

JSON.stringify(url); 
like image 38
Ankit Tyagi Avatar answered Sep 23 '22 04:09

Ankit Tyagi