Sending JSON Response in PHP


Use json_encode() to send a JSON response from a PHP script, commonly used in AJAX requests.

Source Code

$response = ['status' => 'success', 'message' => 'Data fetched successfully'];
header('Content-Type: application/json');
echo json_encode($response);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments