js怎么获取接口返回的值

87次阅读

共计 671 个字符,预计需要花费 2 分钟才能阅读完成。

我想用 js 去请求这个接口 https://api.qqsuu.cn/api/visitor
返回的是 json 格式的数据,想把 ip 的值取出来用,有没有 mjj 知道该怎么写?

网友回复:

注册 google 一下

叼爆小朋友 用 axios。都什么屁事呀!

googlebot2 JSON.parse

李沁峰 ajax fetch axios 方法多了 axios 要三方库 推荐 fetch 吧

nutterchen fetch(‘https://api.qqsuu.cn/api/visitor’)   .then(response => response.json())   .then(data => console.log(data));

Lqdahv var xmlHttp = new XMLHttpRequest(); xmlHttp.open(“GET”, “https://api.qqsuu.cn/api/visitor”, false); xmlHttp.send(null); var result = JSON.parse(xmlHttp.responseText); console.log(result[‘ip’]); 复制代码

jadeborner fetch(‘https://api.qqsuu.cn/api/visitor’)         .then(response=>response.json())         .then(data=>{        console.log(data.ip);  //data.ip 就是要获取的 ip 地址         }) 复制代码

woniu 感谢大佬,这个可行。

正文完
 0