How to get client IP address using jQuery

前端 未结 4 1436

I want to know how to get client IP address using jQuery?

Is it possible? I know pure javascript can\'t, but got some code using JSONP from Stack Overfl

4条回答
  •  隐瞒了意图╮
    2020-11-27 03:20

    jQuery can handle JSONP, just pass an url formatted with the callback=? parameter to the $.getJSON method, for example:

    $.getJSON("https://api.ipify.org/?format=json", function(e) {
        console.log(e.ip);
    });

    This example is of a really simple JSONP service implemented on with api.ipify.org.

    If you aren't looking for a cross-domain solution the script can be simplified even more, since you don't need the callback parameter, and you return pure JSON.

提交回复
热议问题