如何在前端利用ajax获取这些东西?
http://ip.tanwan.com/index.php?action=ipinfo&format=js如何利用ajax获取到里面的这些数据然后再赋值到html中的元素当中?
回复
1个回答
test
2024-07-05
请求类型为document不能用ajax, 回答中的方法就类似CDN引入比如:<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="city"></div>
</body>
<script src="http://ip.tanwan.com/index.php?action=ipinfo&format=js"></script>
<script>
console.log(remote_ip_info);
document.querySelector('.city').innerHTML = JSON.stringify(remote_ip_info)
</script>
</html>
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容