반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 네트워크
- IOS
- vsCode
- ReactNative
- TensorFlow
- localserver
- PYTHON
- avds
- linux
- picker
- VirtualBox
- webpack
- qunit
- 센토스
- Android
- centos
- build
- 맥
- androidstudio
- node
- 개발
- xcode
- jest
- MAC
- Chrome
- MachineLearning
- 리눅스
- unittest
- react
Archives
- Today
- Total
로메오의 블로그
[ajax - php] exception 처리 본문
반응형
Ajax
$.ajax({
url: '/server/address',
method: 'POST',
//dataType: 'json',
data: {
text: ''
}
})
.done(function(json) {
console.log(json)
})
.fail(function(xhr, status, errorThrown) {
console.log('fail', xhr, status, errorThrown)
})
.always(function(xhr, status) {
// console.log('always', xhr, status)
})
PHP
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method != 'POST') throw new Exception('', 1);
try {
if ( empty($text) ) throw new Exception('empty data', 9000);
} catch(Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo json_encode(array(
'error' => array(
'msg' => $e->getMessage(),
'code' => $e->getCode(),
),
));
exit;
}
?>
Postman
반응형
'Backend > PHP' 카테고리의 다른 글
PHP 한글 깨짐 방지 (0) | 2022.03.01 |
---|---|
.PHP 확장자 제거하기 (0) | 2021.08.30 |
PHP에서 긴 문자열 처리 [EOT] (0) | 2021.08.23 |
MAMP 설치하기 [Windows] (0) | 2021.04.27 |
PHP에서 Stored Procedure 호출하기 (0) | 2020.12.09 |
Comments