Welcome Guest, Not a member yet? Register   Sign In
ajax validation in CI with 'jQuery validation plugin'

The client-side validation is working properly.
The validation using ajax request (remote) does not work.

the path for the request is correct..
the validation methods themselves should be correct.

firebug error:
"NetworkError: 500 Internal Server Error - http://localhost:8888/work/ci_buchverwal...zer_exists"

..but the path to the method 'register_benutzer_exists' is correct..

I don't understand what is wrong..any help?

echo '<!-- Start Formular -->';
    $attributes = array('class' => '', 'id' => 'commentForm');
    echo form_open('', $attributes);
    echo form_fieldset($label) . PHP_EOL;
    echo form_error('benutzername') ? '<div ' . $fehler . '>' . PHP_EOL : '<div>' . PHP_EOL;
    echo form_label('Benutzername*:', 'benutzername') . PHP_EOL;
    $data = array('name'           => 'benutzername',
                  'id'             => 'benutzername',);
    echo form_input($data, set_value('benutzername', $benutzername)) . PHP_EOL;
    echo '</div>' . PHP_EOL;
    echo form_fieldset_close() . PHP_EOL;
    echo form_fieldset() . PHP_EOL;
    echo form_button('abbrechen', 'zurück', 'onClick=self.location.href="' . $back_link . '"') . PHP_EOL;
    echo form_submit('submit', $submit_text, 'class="mittel"') . PHP_EOL;
    echo form_fieldset_close() . PHP_EOL;
    echo form_close() . PHP_EOL;

    jQuery(document).ready(function ($) {
                        url:"&lt;?php echo site_url('redaktion/nutzer/register_benutzer_exists'); ?&gt;",
                            benutzername:function () {
                                return $("#benutzername").val();
                    required:'Bitte einen Benutzernamen eingeben',
                    minlength:'Bitte mindestens 2 Zeichen eingeben',
                    remote:'Dieser Benutzername ist schon vorhanden.'
        function register_benutzer_exists () {
            if (array_key_exists('benutzername', $_POST)) {
                if ($this->benutzer_exists($this->input->post('benutzername')) == TRUE) {
                    echo json_encode(FALSE);
                } else {
                    echo json_encode(TRUE);
// Benutzer EXISTS (true or false)
        private function benutzer_exists ($benutzer) {
            $this->db->where('benutzername', $benutzer);
            $query = $this->db->get('bvs_nutzer');
            if ($query->num_rows() > 0) {
                return TRUE;
            } else {
                return FALSE;

You receive a different error message than a "page not found". What you get is an internal server error

Quote:NetworkError: 500 Internal Server Error

In most cases this happens when you have some line of code that makes your sever go like "ermahgerd".
I think the problem causing line(s) are somewhere else because your posted lines look pretty good and faultless. Though there might be an error emerging from
if (array_key_exists('benutzername', $_POST)) {

Try changing it to
if ( $this->input->post('benutzername') ) {

and see if it works.

I've made ​​the change..
remote validation still does not work.
post data in firebug is existing...

view in firebug:
benutzername roberto

The action you have requested is not allowed.
more tips?





Sounds like you have CSRF protection enabled, but aren't sending the CSRF cookie value along with your form values in the ajax call. As far as I know, the error message "The action you have requested is not allowed." is only caused by CSRF.

CSRF protection was enabled, but if the CSRF protection is off
the ajax request should be executed...I understand this correctly?

Unfortunately, the validation still does not work.

I don't understand that...

I'm confused about your urls ...

Your base_url / site_url seems to be " http://localhost:8888/work/ci_buchverwaltung/"

If you call 'redaktion/nutzer/register_benutzer_exists' then you call a controller
named "redaktion" and the included method "nutzer"

In that case "register_benutzer_exists" would be a parameter (send to "nutzer" method)
and not a method.

Or do you route somehow?

actually i will call a controller named 'nutzer' and the included method 'register_benutzer_exists'. the controller 'nutzer' is inside a folder 'named 'redaktion'.

my routing:
$route['default_controller'] = "redaktion/login";
$route['redaktion'] = 'redaktion/login';
$route['redaktion/(:any)'] = 'redaktion/$1';
$route['404_override'] = '';

this should be okay?

I'm no routing expert so I can't comment that Wink

If I were you I would start debugging on an easier level.
First fire a simple ajax request to your validation method and return
a json debug message (log in console). If you get your response go on and add
features. Can be hard to find a bug if you have to many
functionality at once sometime ..

Best wishes - Luckyfella

Theme © iAndrew 2016 - Forum software by © MyBB