javascript - 发出 POST 请求的 S3 静态网站
问题描述
是否可以从托管在 S3 上的静态网站发出 POST 请求?有什么解决方法吗?
解决方案
Totally possible, just use XMLHttpRequest or add some lib (jquery) to help you with that:
<script>
var xhr = new XMLHttpRequest();
xhr.open("POST", '/server', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
// Request finished. Do processing here.
}
}
xhr.send("foo=bar&lorem=ipsum");
// xhr.send(new Int8Array());
// xhr.send(document);
</script>
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
推荐阅读
- c++ - C ++:空字符串而不是输入字符串如果输入字符串比为输入分配的char数组长
- aws-cdk - 如何从 AwsCustomResource (service: 'SecretsManager', action: 'getSecretValue') 返回的 SecretString 中获取纯文本值?
- .net - 在 macOS 上编译 F# 项目时,如何确保编译器可以找到 Mono 程序集“System.Numerics.dll”?
- html - 一个按钮就是不想居中
- javascript - 在打字稿中的类型之间转换时,有没有办法转换底层对象
- r - 如何计算 data.frame 的双边 t.test,其中 X 和 Y 的标准在另一列中指定?
- java - 将 Eclipse 中的 JavaFX 项目导出到可运行的 jar
- vue.js - 在 lunix 上运行 npm run build 时它不起作用
- kotlin - 函数接收器和@RestrictsSuspension
- javascript - 在 react.js 中为测验处理多个单选和复选框