使用Jquery Ajax获取Joomla user_id [英] Get Joomla user_id using a Jquery Ajax

查看:122
本文介绍了使用Jquery Ajax获取Joomla user_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Joomla网站中有以下PHP脚本file.php:

I have the following PHP script file.php in my Joomla site:

$user = JFactory::getUser();
$usr_id = $user->get('id');

如果我直接运行它,则使用HTML:

If I run it directly, using in HTML:

include_once "file.php";

它将获得用户ID,没问题.

It will get the user id, no problem.

但是,如果通过Ajax请求运行它:

However, if run it through an Ajax request:

$.ajax({
    url: "other.php",
...

other.php在哪里:

Where other.php is:

include_once "file.php";

我得到了错误:

Fatal error:  Class 'JFactory' not found in file.php on line 3

为什么?有帮助吗??

Why? Any help!?

推荐答案

您需要导入Joomla库才能使用JFactory类.要导入库,请在文件顶部添加以下内容:

You need to import the Joomla library in order to use the JFactory class. To import the library, add the following to the top of your file:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) ).'/../..' );

require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

这篇关于使用Jquery Ajax获取Joomla user_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆