javascript - 获取 api javascript 返回 html 代码
问题描述
现在我不知道为什么实际上会发生这种情况,而之前 fetch 的功能是在我定位的 url 上正确显示承诺响应。但现在我在console
日志中看到的只是登录页面的 html 代码,我没有更改任何内容,但为什么会发生这种情况?
const caseform = _doc.forms.namedItem('caseform');
caseform.addEventListener("submit", e => {
e.preventDefault();
this._action = caseform["action"];
this._method = caseform["method"];
this._fd = new FormData(caseform);
async function savecase() {
this._params = {method: this._method, body: this._fd};
this._response = await fetch(this._action, this._params);
try {
if(this._response.ok) {
return await this._response.text();
}
} catch(error) {
return error;
}
}
savecase()
.then(result => {
if(result === 'error_in_retention_requirements') {
_doc.querySelector('div[data-result-case-error]').style.display = 'block';
_doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all rentention requirements.';
_doc.querySelector('div[data-result-case-error]').scrollIntoView();
} else if(result === 'error_in_clearance_requirements') {
_doc.querySelector('div[data-result-case-error]').style.display = 'block';
_doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all clearance requirements.';
_doc.querySelector('div[data-result-case-error]').scrollIntoView();
} else if(result === 'error_in_clearance_requirements') {
_doc.querySelector('div[data-result-case-error]').style.display = 'block';
_doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all clearance requirements.';
_doc.querySelector('div[data-result-case-error]').scrollIntoView();
} else {
console.log(result);
}
});
});
这是在控制台日志中返回的返回文本
新案例:136
<!DOCTYPE html>
<html class="no-js" lang="en" dir="ltr">
<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>v1.0</title>
<link rel="icon" href="http://localhost/itd_project/darsystem_v1.0/public/files/img/logo.jpg" type="image/gif" sizes="16x16">
<link rel="stylesheet" href="http://localhost/itd_project/darsystem_v1.0/public/files/foundation/css/foundation.css">
<link rel="stylesheet" href="http://localhost/itd_project/darsystem_v1.0/public/files/foundation/css/app.css">
</head>
<body>
<script>
const _w = window;
const _doc = document;
_w.onload = () => {
const pcode = _doc.querySelector('input[type="password"]');
pcode.onpaste = (e) => {
e.preventDefault();
}
}</script>
<div class="row-login">
<form action="http://localhost/itd_project/darsystem_v1.0/login/check/?attempt=1&for=dXNlcl9sb2dpbg==" method="post" class="stacked" style="color: #272822; ">
<div class="row stacked">
<img class="logo-login" src="http://localhost/itd_project/darsystem_v1.0/public/files/img/logo.jpg"/>
<h5 class="text-center" style="color: #000000; font-size: 12px;">Department of Agrarian Reform</h5>
</div>
<label>ID
<input type="text" name="username" placeholder="ID Number" />
</label>
<label>Password
<input type="password" name="password" placeholder="●●●●●●●●" autocomplete="off" />
</label>
<p>
<button type="submit" class="dar_login button expanded" style=" color: #fff; box-shadow: 0 2px 4px rgba(10, 10, 10, 0.4);">Log in</button>
</p>
</form>
</div>
<footer style="margin-top: 120px;">
<p class="footer">© 2018</p>
</footer>
</body>
</html>
解决方案
推荐阅读
- javascript - 为什么这两个代码块不等价?
- rust - 使用默认值读取环境变量的最高效方法是什么?
- javascript - 如何设置默认 ID 等于项目的 ID(VueJS、VueX、VueComponent、VueRouter)
- python - 扩展基本 html 问题
- mongodb - 如何将 mongodb 输入查询添加到投影结果?
- redis - 某些键空间过期事件未触发(Redis)
- python - Python 中的 Dijkstra 算法耗时太长
- javascript - 如何在同一/当前设置固定位置?
- cuda - 优化我的 Cuda 内核以对火炬张量内的不同索引范围求和
- javascript - 无法读取未定义的属性 scrollIntoView