0

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.

6
  • That site won't let you access its content from your page. The browser will prevent such attempts. Commented Mar 17, 2015 at 19:38
  • And why is that..I followed the syntax given on the site itself... Commented Mar 18, 2015 at 19:10
  • If you check the response headers from loading that URL, you won't see any "Access-Control-Allow-Origin" header. Without that, the browser won't let you see it from a different domain. Commented Mar 18, 2015 at 23:38
  • ipinfo.io supports CORS, so that's unlikely to be the issue. You might be hitting a rate limit though. Try alerting or logging response, rather than response.loc Commented Mar 19, 2015 at 3:19
  • I don't think rate limit is an issue in this case...and about response, the function upon success is not running. There is no alert 'response'. Any other idea?? Commented Mar 20, 2015 at 15:25

1 Answer 1

1

Most likely, you are hitting the "cross-origin problem". See here for more discussion.

Sign up to request clarification or add additional context in comments.

6 Comments

Does not Chromium show this error ?? because I am using it but there is no cors-error in the console.
A lot of browsers are distressingly silent on this issue. If you can open a URL from the Location bar but not from AJAX, it is almost certainly a cross-origin problem.
Even using jsonp this isn't resolved, any other suggestions please.
It's working for me. You don't see any errors in the console?
Do you think its because my internet is behind proxy??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.