我的Ajax請求沒有收到正確的響應!它總是進入readyState'4',響應狀態爲'0'?來自node.js的Ajax響應
客戶端代碼:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("lastNameLabel").innerHTML = "response recieved!";
const responseJSON = JSON.parse(xhttp.responseText);
if(responseJSON.emailTaken == "false"){
window.location = server+"/client/home.html";
}
}
};
xhttp.open("POST", server+"/signUp", true);
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhttp.send("email="+email);
服務器代碼(Node.js的+快遞):
app.post('/signUp', (req, res) => {
res.end("it worked!!");
});
我知道我的服務器處理請求,因爲我看到的URL調用,但響應從來沒有到達HTML客戶端!!我超級卡住了!
它是一個交叉來源請求 - 檢查瀏覽器開發者工具控制檯,看看你是否有任何有關錯誤的錯誤 –
這是什麼意思? –
這意味着檢查瀏覽器**開發人員**工具控制檯的錯誤 –