EDIT : Answers에 언급 된 PHP로 오류를 수정했지만 여전히 동일한 문제가 있습니다.
POST 요청이 실패하면 오류 메시지를 표시하고 실패하지 않으면 성공 메시지를 표시하려고합니다. 현재 성공 메시지를 올바르게 보여주고 있지만 콘솔에서도 SQL을 실패하게하면 아무 일도 일어나지 않습니다.
JQUERY : // 나는 불필요한 코드
제거한 $("#form").validate({
ignore:'',
errorPlacement: function(error, element) {
error.insertAfter(element.parent()); // <- make sure the error message appears after parent element (after textbox!)
},
rules: {
},
messages: {
},
submitHandler: function(form) {
var datastring = $("#form").serialize();
$.ajax({
type: "POST",
url: "myscript.php",
data: datastring,
dataType:"json",
success: function (response) {
if(response.status === "success") {
window.alert(response.comment);
} else if(response.status === "error") {
window.alert(response.comment);
}
}
}); // close $.ajax
} // close submit handler
}); //end validate
PHP :
if($row = sasql_fetch_array($insert))
{
//success message
$arr = array ('status'=>'success','comment'=> $custid);
echo json_encode($arr);
} else {
//error message
$arr = array ('status'=>'error','comment'=>'There has been an error. Please try again.');
echo json_encode($arr);
}
이
사람이 문제가 여기에있을 수있는 일에 대해 어떤 생각을 가지고 있습니까? 내가 말했듯이 을 success
함수 바로 뒤에 추가하면 오류 배열에 아무 것도 반환되지 않습니다. 감사합니다
입니까? –
예 - 응답을 얻지 만 sql이 실패하면 성공합니다. – Janey
문자열 연결에'+'를 사용하고 있습니까? 그것은'.'이어야합니다 ('다시 시도하십시오 '+ $ custid'). – Stryner