The below code snippet explains how to get IP Address of the client machine using JSON and jQuery
<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.getJSON("http://jsonip.appspot.com?callback=?", DisplayIP);
});
function DisplayIP(response) {
$("#ipaddress").html("Your IP Address is " + response.ip);
};
</script>
<span id = "ipaddress"></span>
Explanation:
Above in the document ready event of the HTML page I am executing the jQuery getJSON method which internally makes a JSON call to http://jsonip.appspot.com which is a free web service that determines and returns the IP Address of the machine making the request.
I have also specified a callback function which is executed when the response is received and it displays the IP address in the HTML span with ID ipaddress.
Demo