【发布时间】:2021-09-28 23:53:50
【问题描述】:
我被分配了一项与集成 API 相关的任务。我已经能够从 API 获取信息,但是出现了一个弹出窗口,要求我提交用户名和密码。我有用户名和密码,但我的想法是无需弹出该弹出窗口即可登录。
代码如下:
const getPlate = () => {
let licensePlate = document.getElementById('licensePlate');
let licensePlateNumber = licensePlate.value;
if (licensePlate.value === "") {
alert('¡Debe introducir el número de matrícula para poder avanzar!');
} else {
Axios.get( * URL GOES HERE * ).then((response) => {
let plate = response;
console.log(plate.data[i].make);
});
}
}
<div id="carDataContainer">
<div id="licensePlateContainer">
<input type="text" name="licensePlate" id="licensePlate" placeholder="Matrícula - ej. 001 BNDO"></input>
<button type="button" id="plateBtn" onClick={ getPlate }>Search</button>
</div>
</div>
【问题讨论】:
-
看起来资源需要一个基本授权标头。
-
警报被显示是因为
if也被满足Axios 应该axios.get;你能解释一下I have the username and password部分吗? -
当然。我有访问 API 的凭据并在弹出窗口中提交它工作正常。这个想法是让那个弹出窗口不出现。这是一个付费 API,我的公司要求我将其集成到应用程序中。
标签: javascript node.js reactjs api