jQuery IFrame AJAX DEMO
Send files via iframe
Submit
Show source
Send form via iframe
Show source
Response handling
Show source
Show action2.php source
$isError = !empty($_POST['error']);
$content = json_encode($isError ? ['error' => 'error message'] : ['status' => 'ok']);
if (!empty($_POST['X-Requested-With']) && $_POST['X-Requested-With'] === 'IFrame') {
if ($isError) {
echo '<textarea data-status="400" data-status-text="Bad Request" data-content-type="text/json">' . $content . '</textarea>';
} else {
echo '<textarea data-status="200" data-content-type="text/json">' . $content . '</textarea>';
}
} else {
if ($isError) {
header("HTTP/1.1 400 Bad Request");
}
header('Content-Type: text/json');
echo $content;
}