今天還是用之前六角舉辦的精神時光屋,
提供的API來練習POST,
首先要記得加上
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
並且利用send()
將mail送出,
xhttp.send(JSON.stringify({ email: "user@gmail.com" }));
//創建一個 XMLHttpRequest Object
var xhttp = new XMLHttpRequest();
// 處裡回傳回來的資料
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var result = JSON.parse(xhttp.responseText)
console.log(result);
} else {
console.log(this.status);
console.log(this.readyState);
}
}
// send a request to a server
xhttp.open('POST', 'https://www.thef2e.com/api/isSignUp', true);
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send(JSON.stringify({ email: "user@gmail.com" }));
成功的結果