Все очень просто и понятно на странице формой пишем следующий скрипт:
$('input[name=password]').bind('keyup focus', function() { $.post(base_url + 'index.php/ajax/confirm_database', { server: $('input[name=hostname]').val(), username: $('input[name=username]').val(), password: $('input[name=password]').val() }, function(data) { if (data.success == 'true') { $('#confirm_db').html(data.message).removeClass('failure').addClass('success'); } else { $('#confirm_db').html(data.message).removeClass('success').addClass('failure'); } }, 'json' ); });
проверка будет производиться по средством вызова скрипта index.php/ajax/confirm_database на стороне сервера:
<?php public function confirm_database() { $server = $this->input->post('server'); $username = $this->input->post('username'); $password = $this->input->post('password'); $port = $this->input->post('port'); $host = $server . ':' . $port; $link = @mysql_connect($host, $username, $password, TRUE); if ( ! $link ) { $data['success'] = 'false'; $data['message'] = lang('db_failure').mysql_error(); } else { $data['success'] = 'true'; $data['message'] = lang('db_success'); } // Set some headers for our JSON header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); echo json_encode($data); } ?>