Proxy > Gmail Facebook Yahoo!

Get Client Machine IP Address using JQuery and JSON




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/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 tohttp://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


Responses

0 Respones to "Get Client Machine IP Address using JQuery and JSON"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar