首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法向同一页面发出ajax异步post请求

无法向同一页面发出ajax异步post请求
EN

Stack Overflow用户
提问于 2019-01-04 06:32:17
回答 1查看 19关注 0票数 0

我正在尝试对同一页面进行异步调用,但由于某些原因,异步调用没有进行,因此出现"userinfo“未定义错误!有没有人能告诉我我做错了什么,谢谢!

代码语言:javascript
复制
<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; 
?>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54030713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档