2010-12-10 3 views
1

간단한 웹 페이지의 경우 jQuery의 post()를 통해 PHP 스크립트를 정기적으로 호출하여 데이터베이스를 변경 한 다음 업데이트 된 정보를 얻습니다 뒤로.jquery post() 업데이트 만들기 - 연결 실패/시간 초과 확인

때때로 이러한 호출은 실패하지만 알림이 없습니다.

오류 검사에 가장 좋은 방법을 제안 해 줄 사람이 있습니까? 업데이트가 연결 끊김, 시간 초과 또는 발생할 수 있고 명시 적으로 검사 될 수있는 이유로 실패하는 경우 메시지를 표시 할 수 있습니까?

답변

0

우선 - 서버 측 오류를 제외하기 위해 응답 객체와 함께 성공 이벤트 콜백을 사용하고 있는지 확인하십시오.

$.ajax({ 
    //... other ajax options 
    success: function(response){ 
     alert(response); 
    } 
}); 

귀하의 PHP 스크립트는 이러한 성공의 기능에 대한 응답을 울리는 본질적으로입니다.

$.ajax({ 
    //...other ajax options... 
    timeout: 5000 //5 second timeout 
}); 
: 그것은 "실패"심지어 JSON/ XML 문자열

둘째 ...

당신은 그 오류를 배제하기 위해 시간 제한 옵션을 설정할 수 있습니다, 간단한 문자열 "성공"수

셋째 ...

당신은 어떤 예외에 대한 오류 이벤트 콜백을 사용할 수 있습니다 ...

$.ajax({ 
    error: function(XMLHttpRequest, textStatus, errorThrown){ 
    //handle errors here 
    } 
}); 

A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "notmodified" and "parsererror". This is an Ajax Event . This handler is not called for JSONP requests, because they do not use an XMLHttpRequest.

다음 jQuery docs on ajax

오류에서