Edit after question update
I've updated and commented two of the files where you're having problems
<?php
class modFileFinderHelper
{
function __construct() {
$this->currentdirectory = basename(JPATH_BASE);
}
// static methods only (the constructor above wont run for your ajax request)
public static function FileFinderAjax() {
// Here we get the data passed via ajax - note the values themselves have not been filtered!
$data = JFactory::getApplication()->input->post->get('data',[],'array');
// Presumably you would here do something worthwhile
$response = [
'something' => 12345,
'your_path' => $data['path'],
];
// Usually you can dump json and die, but there's a inbuild responder that'll encode things and die on your behalf
// you'll see client side it also adds a few generic values like "success"
echo new JResponseJson($response);
}
}
jQuery(function($) {
// grab a dom selector so we don't have to grab it each time we update
var filefinder_container = $('#filefinder_container');
function loadContent(path) {
console.log({path: path});
var request = {
option : 'com_ajax',
module : 'filefinder', // to target: mod_filefinder
method : 'FileFinder', // to target: function FileFinderAjax in class modFileFinderHelper
format : 'raw',
data : {path: path}
};
console.log(request);
$.ajax({
method: 'POST',
data: request
})
.success(function(response){
console.log('response: '+response);
// we've got json but we need an object so let's parse it!
response = jQuery.parseJSON(response);
// and now we can use it like this.
filefinder_container.text(response.data.something + " and " + response.data.your_path);
});
}
console.log('onload, calling ajax with default path value: '+$('#filefinder_container').html());
loadContent($('#filefinder_container').html());
$('#path').on('change', function() {
console.log('change event triggered, calling ajax with path value: '+$(this).val());
loadContent($(this).val());
});
});