I have create a nodejs server which will give response as ip address
app.get('/UserIP', function(req, res) {
console.log(req.connection.remoteAddress);
res.send(JSON.stringify({'ip':req.connection.remoteAddress}));
});
later i created a client which will get this ip address
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.getJSON("http://localhost:7979/userip", function (data) {
$('p').html('IP Address is: ' + res.ip);
});
});
</script>
</head>
<body>
<p></p>
</body>
</html>
I cant get that ip to my client website.there are websites like jsonip.com which are working with my code.
please help me in understanding where i m doing mistake.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…