Welcome Guest, Not a member yet? Register   Sign In
AJAX or NO AJAX?
#7

[eluser]Deep Arora[/eluser]
Ok, let me try this...

My custom ajax file looks like this:

Code:
$(document).ready(function() {


     $('#submit_form').click(function() {
        var form_action = $('#form_action').val();
        var user_name = $('#user_name').val();
        var user_password = $('#user_password').val();

        $.post("http://localhost:8080/devbench/index.php/global/login/dologin", { 'user_name': user_name },
              function(data){
                $('#error-msg').replaceWith(data.result);


          }, "json");

    });
});


In my View, I have this to show the login errors;

Code:
<div class="response-msg success ui-corner-all" id="response-msg">
                            <div id="error-msg">Welcome back. Please enter your username and password to continue..</div>
                            </div>


Now, in my controller, I capture login errors at two places.

One, if form validation fails:

Code:
if ($this->form_validation->run() == FALSE)
        {
            $data = array('result' => $this->lang->line('error_missing_fields'));
            echo json_encode($data);
        }

And second, when the user enters invalid login details:

Code:
if (!$this->session->userdata('user_id'))
                    $data = array('result' => $this->lang->line('error_invalid_login'));
                    echo json_encode($data);
            }

The problem happening is that whatever error is encountered first, it keeps showing that error always..i.e., lets say I enter invalid login details, then it shows correct message as "login details invalid"...but then if I remove the username and pwd on the login screen and hits submit again, it still shows the same message...whereas it should show me the first error message "Mandatory fields are missing"...

I refresh the page, and this time, I hit the login button without entering anything..it shows the correct message "Mandatory fields are missing"...but now if I enter login details and hit submit, it still shows the same message, instead of "login details invalid"..

I should be doing something stupid..I guess I need to reset that array that gets passed to json_encode somewhere, I tried but it doesnt work...

any help??


Messages In This Thread
AJAX or NO AJAX? - by El Forum - 01-15-2010, 01:55 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:15 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:23 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:23 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:12 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:40 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:59 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 07:12 PM
AJAX or NO AJAX? - by El Forum - 02-10-2010, 11:59 AM
AJAX or NO AJAX? - by El Forum - 02-11-2010, 06:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB