Zoya
Zoya

Reputation: 405

I want to show users their location on my web site in asp.net

On page load users the page shall display the location of the user using ip address, I have this javascript this fetches me the location but instead of alert i want it to display in a label control or something

<script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script type="text/javascript" language="Javascript" src="http://api.easyjquery.com/easyjquery.js"></script> 

<script type="text/javascript" language="Javascript">

    // 1. Your Data Here
    function my_callback(json) {
        alert("IP :" + json.IP + " COUNTRY: " + json.COUNTRY);
    }

    function my_callback2(json) {
       alert("IP :" + json.IP + " COUNTRY: " + json.COUNTRY + " City: " + json.cityName + " Region Name: " + json.regionName);
    }

    // 2. Setup Callback Function
    // EasyjQuery_Get_IP("my_callback");      // fastest version
    EasyjQuery_Get_IP("my_callback2","full"); // full version

</script> 

Upvotes: 0

Views: 579

Answers (1)

powtac
powtac

Reputation: 41040

Add a additional div into the body tag of your website:

[...]
</head>
<body>
[...]
<div id="location">Loading location...</div>

Update your JavaScript, instead of the lines starting with alert() use:

document.getElementById('location').innerHTML = "IP: " + json.IP + " Country: " + json.COUNTRY + " City: " + json.cityName + " Region Name: " + json.regionName;

Working example: http://jsfiddle.net/powtac/gJKue/6/

Upvotes: 1

Related Questions