在前臺(tái)使用formData封裝數(shù)據(jù)并通過xhr對(duì)象發(fā)送請(qǐng)求時(shí)發(fā)現(xiàn)formData中的數(shù)據(jù)放不進(jìn)去的問題:代碼: function register() { const username = document.getElementById('input').value; //已驗(yàn)證可獲取到 const psw = document.getElementById('psw').value;//已驗(yàn)證可獲取到 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的值發(fā)現(xiàn)為空:
關(guān)于formData放入數(shù)值對(duì)象失敗
www說
2018-12-20 18:14:43