js获取当前所在地的省份、城市名称

时间:2022-03-19 20:32:21

  <script src="../js/jquery.js" type="text/javascript"></script/>
  <script src="../user/js/jquery.cityselect.js" type="text/javascript"></script>
  <script type="text/javascript" src="http://int.dpool.sina.com.cn/iplookup/iplookup.php? format=js"></script>  //新浪接口

<script language="javascript" type="text/javascript">

        var myprovince = remote_ip_info['province'];
        var mycity = remote_ip_info['city'];
        var mydistrict = remote_ip_info['district'];      
        var userName ='<%=loginUserName %>';
        var city = myprovince + ' ' + mycity;
        var ip = '<%=Ip%>';
        var machName = '<%=machName %>';
        var flag = '<%=flag%>';    
        $(function() {
        $.ajax({
        url: 'ajaxHandlerSecure.ashx?m=insertcity' + "&flag=" + flag + "&machName=" + machName + "&ip=" + ip + "&userName=" + userName + "&city=" + city + '&ran=' + Math.random(),  //异步请求后台操作
            type: "POST",
                success: function(data) {
                    alert(data);
                }, error: function() {
                    alert("添加失败!");
                }
            });
        }); 

</script>

 

后台.cs 写入需要保存当前城市信息的方法。