【发布时间】:2014-01-16 00:25:46
【问题描述】:
我希望能够通过 AJAX 调用对 Joomla 中的用户进行身份验证,以便在登录不正确时创建错误效果,并在登录正确时重定向用户。
我更愿意通过 JQuery 的 .ajax API 来实现。
另外,我是否需要以某种方式初始化 JQuery,或者它已经存在,你只需要使用“JQuery”而不是“$”?
【问题讨论】:
标签: javascript jquery ajax authentication joomla
我希望能够通过 AJAX 调用对 Joomla 中的用户进行身份验证,以便在登录不正确时创建错误效果,并在登录正确时重定向用户。
我更愿意通过 JQuery 的 .ajax API 来实现。
另外,我是否需要以某种方式初始化 JQuery,或者它已经存在,你只需要使用“JQuery”而不是“$”?
【问题讨论】:
标签: javascript jquery ajax authentication joomla
试试这个,
您可以使用 Joomla 的登录选项进行 Ajax 登录验证。
通过 post 收集您的用户名和密码并设置为数组。
$options = array();
$options['remember'] = JRequest::getBool('remember', false);
$data['username'] = JRequest::getVar('username', '', 'method', 'username');
$data['password'] = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
$credentials = array();
$credentials['username'] = $data['username'];
$credentials['password'] = $data['password'];
$app = JFactory::getApplication();
$error = $app->login($credentials, $options);
if (!JError::isError($error)) {
// login success
}
else{
//Failed attempt
}
如果你有任何自定义组件,上面的代码部分可以写在你的任何控制器函数中。如果您使用的是Joomla3.x,您可以使用com_ajax 来完成此任务。
var data = "";//set your user name and password
jQuery.ajax ({
type: "POST",
url: "index.php?option=com_ajax&task=loginauth",
data: data,
success: function(data) {
}
});
当您在应用程序中包含 jQuery 库时,只需使用 jQuery 访问它
'$' 用于 Joomla 中的 moo-tools。对于包含 jQuery 库,您只需编辑模板文件 templates/yourtemplate/index.php
希望对您有所帮助..
【讨论】:
If your are using Joomla3.x you can use com_ajax for this task. >> 您也可以将 com_ajax 用于 Joomla 1.5 和 2.5,但您需要手动下载(github)并安装它;)