在前台使用formData封装数据并通过xhr对象发送请求时发现formData中的数据放不进去的问题:代码: function register() { const username = document.getElementById('input').value; //已验证可获取到 const psw = document.getElementById('psw').value;//已验证可获取到 var formData = new FormData(); formData.append('username', username); formData.append('psw', psw); console.log(formData); var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) { alert(xhr.responseText); } else { alert("Response was unsuccessful:" + xhr.status); } } }; xhr.open("post", "http://localhost:3000/register", true); xhr.send(formData);在客户端输出formData的值发现为空:
添加回答
举报
0/150
提交
取消