请用中文回答在js文件中怎样用http://127.0.0.1:8980/js/a/authInfo接口获得数据
时间: 2023-12-18 12:02:51 浏览: 34
在JavaScript文件中,您可以使用AJAX技术(Asynchronous JavaScript and XML)通过HTTP协议从服务器获取数据。您可以使用XMLHttpRequest对象来发送请求并获取响应。以下是一个简单的示例代码:
```
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://127.0.0.1:8980/js/a/authInfo', true);
xhr.onload = function () {
if (xhr.status === 200) {
// 请求成功,获取响应数据
var data = xhr.responseText;
console.log(data);
} else {
// 请求失败,处理错误
console.error('请求失败: ', xhr.statusText);
}
};
xhr.onerror = function () {
console.error('请求出错了');
};
xhr.send();
```
请注意,此处使用GET方法请求URL为'http://127.0.0.1:8980/js/a/authInfo'的数据。您可以根据自己的需要使用其他HTTP方法(例如POST、PUT等)或不同的URL来获取不同的数据。