Pages

Friday, 7 June 2013

How TO Get JSON Data/Response From URL in JavaScript Using jQuery in C# Asp.Net

How TO Get JSON Data/Response From URL in JavaScript Using  jQuery in C# Asp.Net

Program:

Method 1:

<script type="text/javascript">
    $(function () {
        $("#btnSubmit").click(function () {
            $.getJSON("http://jsonip.appspot.com?callback=?",
function (data) {
    alert("Your IP Address: " + data.ip);
})
.error(function () { alert("error"); })
        });
    });
</script>

Method 2:


<script type="text/javascript">
    function yourmethod(data) {
        alert('City : ' + data.city + ' Country name : ' + data.countryName);
    }
</script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=yourmethod"></script>

No comments:

Post a Comment