Search code examples
phpjoomla

Joomla 4 - AJAX | com_ajax - server error 500


In Joomla 4 I can't get com_ajax working. I'm using jQuery 3.6; I created a module mod_ajax and installed successfully but calls to com_ajax doesn't work, why?

// mypage.html

  link = "index.php?option=com_ajax&module=ajaxx&format=json&task=100" ;
  $.post(link,  function(data, status){  });    

// mod_ajaxx.php

$path= JPATH_ROOT."/modules/mod_ajax/";
$opt=$_POST['option']; $uri= $_SERVER['REQUEST_URI'];
$name=$_POST['task']; 
$tmp = "\n\r  opt:".$opt."\n\r  uri:".$uri ."\n\r  task:".$task;  
file_put_contents( $path.'log.txt',  $tmp)  ;

// log.txt

  opt: 
  uri:/jomkop/index.php?option=com_content&view=article&id=12&Itemid=126
  task:

Devtools return error 500 on this link, why? https://www.example.com/jomkop/index.php?option=com_ajax&module=ajax&format=json&task=1-save_form-0-0

Where are my URL variables? According to Joomla: "Additional variables and values used by your extension may also be included in the URL." - https://docs.joomla.org/Using_Joomla_Ajax_Interface I tried with helper.php as well, same result. My Joomla: 4.0.1

Thank you!


Solution

  • I found a solution by loading Joomla API in my php script. Thanks