Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  23] [ 7]  / answers: 1 / hits: 82406  / 11 Years ago, thu, november 21, 2013, 12:00:00

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);
});
});

More From » node.js

 Answers
45

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



JSON.stringify(url)


not -



Json.stringify(url)


See the docs.


[#74148] Wednesday, November 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kadinl

Total Points: 321
Total Questions: 117
Total Answers: 103

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;