View on GitHub

jQuery IFrame AJAX DEMO

Library provides transport to emulate AJAX via hidden iframe. In the first place necessary for AJAX uploading files to older browsers do not support the XMLHttpRequest 2.

Download this project as a .zip file Download this project as a tar.gz file

jQuery IFrame AJAX DEMO

Send files via iframe

Show source

Send form via iframe

Show source

Response handling

Trigger error

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;
}