ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

jQuery script problem

February 08, 2008 2:27pm

Subscribe [2]
  • #1 / Feb 08, 2008 2:27pm

    Edemilson Lima

    241 posts

    I have a little problem with my first jQuery script… It makes an AJAX post to a controller that check if an Email exists or not in the database. If it don’t exist, the controller returns a string to the Javascript. I did check with Firebug and everything is working. The AJAX gets the string back, but the callback function is not being executed. It should display the string in an alert box, but it doesn’t.

    My view file is:

    
    
    

    My email_check.js file is:

    $('#email').blur(function() {
      $.post(
        'http://www.mysite.com/login/check/',
        { email: $('#email').val() },
        function(data,textStatus) {
          alert("Data Loaded: "+data);
          $('#login_msg').html(data);
        },
        'json'
      };
    });

    It should show the alert() above, but the callback function is not executed. May I am returning an invalid data type to it? I did this script based in an example in the manual.

    The controller it calls is:

    class Check extends Controller {
    
        function Check() {
            parent::Controller();
            $this->load->model('users/profiles_model','profiles');
        }
        
        function index() {
            $email=$this->input->post('email');
            $result=$this->profiles->get_user_by_email($email);
            if(!$result) {
                echo 'Invalid E-mail address: '.$email;
            }
        }
        
    }

    The string is being returned, I can see it with Firebug.

  • #2 / Feb 08, 2008 4:51pm

    Pascal Kriete

    2589 posts

    Hmm, I guess I’ll try…

    $('#email').blur(function() 
    {
        $.post('http://www.mysite.com/login/check/', { 
            email: $('#email').val() 
        },
        function(data,textStatus) {
            alert("Data Loaded: "+data);
            $('#login_msg').html(data);
        },
        'json' /* a 4th parameter? */
        };/* what does this close?? */
    });

    I don’t know where the json parameter should go - if at all - but that seems like a bad place for it 😉.

  • #3 / Feb 08, 2008 5:52pm

    CI jforth

    13 posts

    doesn’t look like your returning json. take it out.

    $('#email').blur(function(){
                        $.post('http://www.mysite.com/login/check/', {
                            email: $('#email').val()
                        }, function(data){
                            alert("Data Loaded: " + data.text());
                            $('#login_msg').html(data.text());
                        });
                    });
  • #4 / Feb 08, 2008 6:00pm

    Edemilson Lima

    241 posts

    Hmmmm… That closer appear to be in excess, but it is a closer parenthesis for $.post(). I don’t know how, but I typed it wrong in my post above.

    The fourth parameter is at the jQuery docs:

    http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

    I used it to specify that my post data was in JSON format (I thought it was used for send data), but as my PHP script is getting a normal post (not JSON encoded), you’re right, it is unnecessary!
    It is working now, thank you very much!  😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases