javascript - 更改 onload xmlhttprequest javascript 上的表单值?
问题描述
if (xhr.status === 200) {
alert(xhr.responseText+document.getElementById("thatid").value);
document.getElementById("thatid").value = xhr.responseText;
//document.getElementById("f3").value = 'yayayay';
}
<form>
<button id="thatbtn" value="submit" >
<input type="hidden" id="thatid" value="bob" >
</form>
基本上警报有效并打印 xhr.responsetext,但它不会更改表单上的“thatid”输入
<div id="f5" style="display:none;"></div>
xhr.onload = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
dude = xhr.responseText;
f5.innerHTML = dude;
alert(dude+f5.innerHTML);
//this does change the innerHTML
//however, trying to read f5.innerHTML outside of onload
//function will read '' or none, y not persistent?
}
else if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
}
};
警报(f5.innerHTML);//没有文本
解决方案
推荐阅读
- go - 在 IBM Cloud 中上传对象时如何修复“NoCredentialProviders:链中没有有效的提供者。已弃用”
- arrays - ESP32 Arduino 在 PSRAM 中分配和使用结构数组
- python - 更改一列 Pandas Python 中的字符串值
- angular - 角度动画 [@.disabled] 冻结页面
- .net-core - SmartFormat - 覆盖格式方法
- machine-learning - 二进制分类问题:如何处理严重的数据不平衡?
- rest - 关于 REST 请求和响应中的 Content-Type 标头的问题
- exchange-server - 邮件递送限制
- php - Lighttpd:我可以将 http 错误响应重定向到 error.php 处理程序吗?
- mysql - 在 MySQL 中有条件地在列中插入值