gpt4 book ai didi

jquery - jsonp回调问题

转载 作者:行者123 更新时间:2023-12-01 02:36:36 25 4
gpt4 key购买 nike

我正在尝试使用以下代码来检索客户端 IP,并且效果很好

<script type="text/javascript">  
function getip(json) {
var ip = json.ip; // alerts the client ip address
alert(ip);
}
</script>
<script type="text/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>

但是当我用 $.ajax 尝试它时,它什么也没做......

    $.ajax({
type: "GET",
url: 'http://jsonip.appspot.com/?callback=getip',
dataType: "jsonp",
success: function getip(json) {
alert("sucess");
var ip = json.ip;
alert(ip);
}

});

});

请帮忙

最佳答案

$.ajax({
type: "GET",
url: "http://jsonip.appspot.com/?callback=?",
// ^
// ---- note the ? symbol ----------------|
// jQuery is responsible for replacing this symbol
// with the name of the auto generated callback fn
dataType: "jsonp",
success: function(json) {
var ip = json.ip;
alert(ip);
}
});

jsFiddle demo在这里。

关于jquery - jsonp回调问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4942004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com