post
요청 중에 오류를 catch하는 방법 javascript? 나는 readyState == 4
요청이 완료되었다는 것을 의미하고, status==200
이 요청이 성공했다는 것을 의미하는지를 안다. 게시물 요청이 실패 할 때 인터넷 연결이 실패하거나 잘못된 값이되었다는 메시지가 표시됩니다.자바 스크립트 게시/요청 읽기 캐치 오류
현재이 같은 일이, 모달 괜찮 작동하고있을 때의
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
// document.getElementById("demo").innerHTML = xhttp.responseText;
hideToolbar();
console.log('Saving successful.');
} else if(xhttp.status == "failed"){
console.log('Sorry there is a problem.');
}
};
var data = JSON.stringify({
"name":"name",
"definition":diagramData
});
xhttp.send(data);
당신은 오류 처리에 대한 다른 상태 코드와 readystates를 확인, 또는 [Ajax 요청이 자바 스크립트에 실패했다 경우 검지]의 try/catch 블록 –
가능한 복제를 실행할 수 있습니다 (http://stackoverflow.com/questions/22925803/detect-if-ajax-request-had-failed-in-javascript) –
'.onload'를 듣고 있다면 readyState – maioman