I've been following this tutorial to make an AJAX login form: http://www.mysite4u.net/joomla-articles/jquery-ajax-joomla-login.html

But I can't get it to work. The ajax call doesn't work. It gives me this error:

Uncaught TypeError: Cannot read property 'loggedIn' of null

I tried reading this documentation, but I guess that it is not the AJAX component that is used in this, and it doesn't mention anything about calling components: https://docs.joomla.org/Using_Joomla_Ajax_Interface

This is my AJAX call:

form = jQuery('#userForm'); 

    url: 'index.php?option=com_content&format=ajax&view=article&task=loginUser&tmpl=component',
    type: 'post',
    dataType: 'html',
    data: {
        form: jQuery(form).serializeArray()
    async: true,
    success: function(response){
        var result = jQuery.parseJSON(response);

        if ( result.loggedIn == 1 ) {                   
            //User logged in                    
        else {                  
            //User not logged in                    

And the function inside components/com_content/views/article/view.ajax.php ("view.ajax.php" is a file I've created):

public function _logInUser( $form ){
    $options = array();
    $credentials = array();

    $credentials['username'] = $form[0]['value'];
    $credentials['password'] = $form[1]['value'];

    $result = JFactory::getApplication()->login($credentials, $options);        
    $result = ($result) ? 1 : 0;

    //1     - logged in
    //0     - not logged in     
    echo json_encode( array('loggedIn' => $result) );                   
  • to JonasB: No, the tutorial mentioned contains THE IMPORTANT PART. Please go trough the tutorial more carefully. Unfortunately It was you who missed the part. Nov 11, 2018 at 16:11

2 Answers 2


Apperently I was missing an important part. I needed to have the "loginUser" task addded to the switch in view.ajax.php like:

function display($tpl = null)
    $task = JRequest::getString('task');        
    switch( $task ){                        
        case "registerNewUser":         
            $this->_registerNewUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );             
        case "loginUser":           
            $this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );               

Maybe I misunderstand you in your question but in the directory of com_content/views/article you cannot/should not create a view.html.php file since it originally has a good view.html.php file.

In the tutorial which you follow the author says that you should create an 'view.ajax.php' file in com_content/views/article folder (not a view.html.php file). Maybe that is causing your problem since you created a wrong file for this ajax call.

And if that is just a mistake in your question, then you also might want to study this earlier answer about ajax calls within Joomla here (it is better not to repeat that here): What is the proper way to make an AJAX call in component?

  • Woops, my fault... It is a view.ajax.php I've created. Thanks for your suggestion! Oct 12, 2018 at 10:12
  • I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
    – Zollie
    Oct 12, 2018 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.