我正在尝试对同一页面进行异步调用,但由于某些原因,异步调用没有进行,因此出现"userinfo“未定义错误!有没有人能告诉我我做错了什么,谢谢!
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready(function() {
//getting location of the user and assigning it to the variable
$.get("http://ipinfo.io", function (response) {
var usercity=response.city;
console.log(usercity);
$.ajax({
//no need to provide url since we are making async call on the same page
type: "post",
data: {cityinfo:usercity},
});
}, "jsonp");
});
</script>
<?php
session_start();
$usercity=$_POST['cityinfo'];
echo $usercity;
?>
https://stackoverflow.com/questions/54030713
复制相似问题