Reputation: 1658
I am trying to use ipinfo api in my django app.
my js code -
var button = document.getElementById('login_button');
var user_location = document.getElementById('user_location');
button.onclick=function()
{
get_location();
form.submit();
}
function get_location()
{
alert('inside');
$.get('http://ipinfo.io', function(response)
{
alert('response');
user_location.value = response.loc;
console.log(response.loc);
alert(response.loc);
}
,'jsonp');
}
my html code(relevant)-
<div class="row">
<form id="form" method="post" class="form">
{% csrf_token %}
<input type="hidden" id="user_location" name="user_location"/>
</form>
</div>
<div class="row">
<button type="button" id="login_button" name="confirm_login" class="tooltip-test btn btn-sm btn-success" title="Click to Log In">
Login
</button>
</div>
and my views.py relevant code -
o = online_status(username = u.username, location = post['user_location'])
devices_no = 1
o.save()
My problem starts with the js file. It is alerting 'inside' but niether it alerts 'response' nor there is any thing in my browser console and also there is no alert of response.loc.
Where I am wrong..??
Help me please.
Note: My internet is behind a proxy.
Thanks in advance.
Upvotes: 0
Views: 381
Reputation: 44396
Most likely, you are hitting the "cross-origin problem". See here for more discussion.
Upvotes: 1