0
I PHP 스크립트를 호출 jQuery로 AJAX를 호출하고 그래서 같이 success
또는 error
기능을 다시 JSON 형식으로 일부 정보를 반환 있습니다반환 JSON 후 PHP PDO 트랜잭션 롤백
$.ajax({
url: 'crud/clients.php',
dataType: 'json',
type: 'POST',
data: {
oper:'add'
,id:''
,clientID:$('#clientID_add').val()
},
async: false,
success: function(data){
alert(data.errorsExist);
},
error: function(data){
alert(data.appError);
}
});
가있다 PHP 스크립트는 호출되는 : 나는 오류 처리 및 디버그 내 IDE에서 내 코드를 테스트 할 때
try {
// Begin a transaction, turning off autocommit
$dbh->beginTransaction();
// Client INSERT
$sthClients->execute($crudColumnValues);
// Get the ID from the client we just INSERTED
$lastInsertID = $dbh->lastInsertId();
// Activity INSERT
$sthActivity->execute();
// commit the queries
$dbh->commit();
}
catch (PDOException $e) {
// Close the connection
$dbh = null;
// Echo back JSON
echo '{"appError": "'.$e->getMessage().'", "errorsExist":"Y"}';
// rollback the transaction
$testing = $dbh->rollBack();
exit();
}
는 PHP 파일은 rollBack();
전화에서 멈추고 내 JSON 다시 롤백 후 내 AJAX 호출에 에코 결코 극복.
rollBack
을 호출하면 해당 JSON을 내 AJAX 함수로 되 돌리는 방법이 있습니까? 어쩌면 이것 때문에
네! 그것이 문제였습니다. 'rollback' 다음에'$ dbh = null'을 넣어야합니까, 아니면 전혀 필요하지 않을 수도 있습니다 ...? – FastTrack
명시 적으로 연결을 닫지 않으면 PHP가 자동으로 닫습니다. '$ dbh = null'을 제거 할 수 있습니다. – galymzhan