首页 > 解决方案 > 发出 POST 请求的 S3 静态网站

问题描述

是否可以从托管在 S3 上的静态网站发出 POST 请求?有什么解决方法吗?

标签: javascriptpostamazon-s3static

解决方案


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


推荐阅读