Run function in com_content with ajax - doesn't call it corretly
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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 dosen'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 dosen't mention anything about calling components: https://docs.joomla.org/Using_Joomla_Ajax_Interface
This is my AJAX call:
form = jQuery('#userForm');
jQuery.ajax(
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)
console.log(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
The "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) );
jexit();
joomla-3.x ajax
add a comment |Â
up vote
1
down vote
favorite
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 dosen'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 dosen't mention anything about calling components: https://docs.joomla.org/Using_Joomla_Ajax_Interface
This is my AJAX call:
form = jQuery('#userForm');
jQuery.ajax(
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)
console.log(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
The "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) );
jexit();
joomla-3.x ajax
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 dosen'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 dosen't mention anything about calling components: https://docs.joomla.org/Using_Joomla_Ajax_Interface
This is my AJAX call:
form = jQuery('#userForm');
jQuery.ajax(
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)
console.log(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
The "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) );
jexit();
joomla-3.x ajax
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 dosen'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 dosen't mention anything about calling components: https://docs.joomla.org/Using_Joomla_Ajax_Interface
This is my AJAX call:
form = jQuery('#userForm');
jQuery.ajax(
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)
console.log(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
The "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) );
jexit();
joomla-3.x ajax
joomla-3.x ajax
edited 30 mins ago
asked 1 hour ago


JonasB
1608
1608
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
Apperently the tutorial was missing an important part. It 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') );
break;
case "loginUser":
$this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );
break;
jexit();
add a comment |Â
up vote
1
down vote
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 aview.ajax.php
I've created. Thanks for your suggestion!
– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Apperently the tutorial was missing an important part. It 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') );
break;
case "loginUser":
$this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );
break;
jexit();
add a comment |Â
up vote
1
down vote
Apperently the tutorial was missing an important part. It 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') );
break;
case "loginUser":
$this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );
break;
jexit();
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Apperently the tutorial was missing an important part. It 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') );
break;
case "loginUser":
$this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );
break;
jexit();
Apperently the tutorial was missing an important part. It 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') );
break;
case "loginUser":
$this->_logInUser( JFactory::getApplication()->input->post->get('form', NULL, 'ARRAY') );
break;
jexit();
answered 20 mins ago


JonasB
1608
1608
add a comment |Â
add a comment |Â
up vote
1
down vote
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 aview.ajax.php
I've created. Thanks for your suggestion!
– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
add a comment |Â
up vote
1
down vote
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 aview.ajax.php
I've created. Thanks for your suggestion!
– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
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?
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?
edited 20 mins ago
answered 48 mins ago
Zollie
565
565
Woops, my fault... It is aview.ajax.php
I've created. Thanks for your suggestion!
– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
add a comment |Â
Woops, my fault... It is aview.ajax.php
I've created. Thanks for your suggestion!
– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
Woops, my fault... It is a
view.ajax.php
I've created. Thanks for your suggestion!– JonasB
29 mins ago
Woops, my fault... It is a
view.ajax.php
I've created. Thanks for your suggestion!– JonasB
29 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
I added a link in my answer about the proper ajax calls in Joomla, if you did not study that before.
– Zollie
17 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fjoomla.stackexchange.com%2fquestions%2f23583%2frun-function-in-com-content-with-ajax-doesnt-call-it-corretly%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password