当我将ajax发送到某个*.php文件时,我不能在其中使用joomla。我该怎么用呢?试图插入以下内容
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..'.DS.'..'.DS.'..'));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');但是get:未能打开流:/siteurl/库/php/adduser.php中没有这样的文件或目录
$.ajax({
type: 'POST',
url: '/libraries/php/adduser.php',
data:,
success: function(result) {
console.log(result);
},
error: function(jqxhr, status, exception) {
console.log(exception);
}
})发布于 2018-02-16 14:39:29
$mainframe是我们调用曼博核心的方式,如果我没记错的话,请原谅我的记忆一定是2006年。从DS分隔符判断,我认为您最好是遵循Joomla1.5中的指南。
引导Joomla在任何/cli文件中都有很好的解释:最简单的是garbagecron,这是相关的部分,只需调整路径:
<?php
/**
* @package Joomla.Cli
*/
const _JEXEC = 1;
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
class GarbageCron extends JApplicationCli
{
public function doExecute()
{
// your code here
}
}
JApplicationCli::getInstance('GarbageCron')->execute();发布于 2018-02-16 22:48:17
如果在自定义组件中使用ajax,可以创建ajax视图和自定义视图格式示例view.ajax.php,然后使用以下代码使用jquery:
$.ajax({
url: '<?php echo JUri::base().'index.php' ?>',
type: 'POST',
data: {
'data':data,
'option': 'com_custom',
'view': 'ajax',
'tmpl':'component',
'format': 'ajax'
},
beforeSend: function(){
},
success: function(data){
}
});现在您可以在view.ajax.php文件中使用所有joomla。
https://stackoverflow.com/questions/48813967
复制相似问题