js获取post请求参数

在 js 中获取 POST 请求的参数需要使用 XHR 对象。

首先,创建一个新的 XHR 对象:

var xhr = new XMLHttpRequest();

然后,打开一个请求:

xhr.open("POST", "your_url", true);

设置请求头,以告诉服务器请求的内容类型是 application/x-www-form-urlencoded:

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

最后,通过 send() 方法发送请求,并在请求完成后使用 responseText 属性获取响应:

xhr.send("param1=value1&param2=value2");

xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { console.log(xhr.responseText); DNodeJS