PHP를 사용하여 서버 오류 응답을 보내는 방법은 무엇입니까?
문제
사용자가 클릭하자마자 버튼 삭제 내 jQuery 스크립트는 서버에 선택한 항목을 삭제하도록 요청합니다.
이제 나는 내 것을 원한다 PHP 성공 또는 오류 응답을 보내는 스크립트.
~하는 것이 가능하니 오류 콜백을 발사하십시오 항목을 삭제할 수없는 경우?
감사
내 jQuery 코드 :
$.ajax({
type: "post",
url: "myAjax.php" ,
dataType: "text",
data: {
some:data
},
error: function(request,error)
{
// tell the user why he couldn't delete the item
// timeout , item not found ...
},
success: function ( response )
{
// tell the user that the item was deleted
// hide the item
}
);
해결책
header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500); // 500 internal server error
// etc etc..
체크 아웃 헤더() 더 많은 옵션. 모든 HTTP 오류 코드를 사용할 수 있습니다.
관련 질문 : asp.net MVC를 사용하여 jQuery ajax 호출에서 "오류"콜백을 어떻게 트리거합니까?
제휴하지 않습니다 StackOverflow