ajax - 从文本字段中获取值并使用 AJAX 请求 Javascript 发送它
问题描述
我正在尝试同步客户端和服务器端脚本,客户端从文本框中获取一个值并将其发送到服务器,服务器在服务器上将该输入显示为 cookie。
这是我到目前为止的代码
function loadCookie() {
//[1] make a new request object
var xhttp = new XMLHttpRequest();
//[2] set the request options
xhttp.open("GET", "index.html", true);
//[3] define what you will do when you ge a response (callback)
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {
document.getElementById("input_response").innerHTML = this.responseText;
}
};
//[4] finally send out the request
xhttp.send();
}
我有 和 按钮,但我遇到了页面重新加载本身的问题,而不是获取输入的值并将其显示为服务器中的 cookie。我怀疑它与 index.html 的 URL 有关
解决方案
推荐阅读
- server-side-rendering - 使用 tossr 解决 SSR 问题: throw new ERR_INVALID_ARG_TYPE('target', ['Buffer', 'Uint8Array'], target);
- python - Python 3.9.1 安装错误的 img2pdf
- ruby - 从字符串生成嵌套哈希
- ssh - Rsync 无法连接
- php - 如何在 Symfony 中实现你自己的 Faker 提供者
- google-apps-script - 谷歌表函数 myfunction() 解释了吗?
- azure - Azure DevOps 构建 YML 不是条件不工作
- node.js - Macbook m1节点js docker镜像构建失败
- ruby-on-rails - 使用 ActiveRecord 锁定回调内的关联?
- javascript - 在 JS 中编辑 JSON 并将其放入数组中