原生JS發請求

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); } }; xhr.open('post', gDatagridUrl, true); xhr.setRequestHeader("Authorization", sessionStorage.getItem("token")); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Accept", "application/json"); // xhr.onload = function () { // if (this.status == 200) { // var res = this.response; // console.log(res) // } // }; xhr.send();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章