1

Please help me with a problem - get function not working for http://wtfismyip.com/text or http://www.passwordrandom.com/query?command=ip

Code:

<span id="global_ip" class="global_ip">global ip - get test</span>
<script type="text/javascript">
$('#global_ip').click(function () {  
    alert('click!');      
    $.get({
        type: "GET",
        url: "http://www.passwordrandom.com/query?command=ip",
        dataType: "text"
    }).done(function (res) {
        alert(res);
    }).fail(function (jqXHR, textStatus, errorThrown) {
        alert("Call failed: " + textStatus + ", " + errorThrown);
    });
});

GRUNGER
  • 486
  • 3
  • 14

2 Answers2

1

You cannot do this, it's a violation of same origin policy.

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, port, or protocol.

But this could help you achieve what you want: Get ip address with javascript

Community
  • 1
  • 1
miklosme
  • 761
  • 1
  • 5
  • 19
0

Try this:

    <span id="global_ip" class="global_ip">global ip - get test</span>
        <script type="text/javascript">
                $('#global_ip').click(function()
                {
                        $.get("http://www.passwordrandom.com/query?command=ip", function(data)
                        {
                                alert(data);
                        });
                });
</script>
Rayon
  • 36,219
  • 4
  • 49
  • 76