无法在此jquery方法中声明全局变量。我缺少什么,怎么做?
var info = "empty";
$.get("http://ip-api.com/json", function(response) {
info = response.city;
}, "jsonp");
console.log(info);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
答案 0 :(得分:0)
您可以将变量设置为
var info = "";
$(document).ready(function(){
$.get("http://ip-api.com/json", function(response) {
info = response.city;
console.log(info);
}, "jsonp");
});