0

i have coded a little component to administrate books for a histroy club. I added some views to deiplay different tables with book date. So far everythign works.

In fact the DB access and the building of the table and stepping thru the custom fields takes a bit and so i would like to add a kind of "Loading message" to the view. Until now i added the loading message and the AJAX call to the view ... the loading message apperars and the AJAX call is done. But in fact nothing happens.

Thats the call from the default.php so far

<script type="text/javascript">
    function GetDataFromDB() {
        $.ajax({type: 'POST', 
                url: 'index.php?option=com_literaturverzeichnis&view=gesamtajax&task=GetBookDataFromDB',
                data: {action: 'gesamt'},       
                cache: false
                success: function(data){
                    alert("success");
                },      
                error:function(){
                    alert("error");
                }
        });         
    }
    (function ($) {
        $(window).load(function(){
            document.getElementById("resultdiv").style.display = "none";
            document.getElementById("btnprint").style.display = "none";
            document.getElementById("loadingdiv").style.display = "block";
            document.getElementById("loader").style.display = "block";
            GetDataFromDB();
        });
    })(jQuery);
</script>

And thats the controller.php of the component.

class LiteraturverzeichnisController extends JControllerLegacy
{   
    function GetBookDataFromDB() { echo "<p>WORKS FINE</p>"; }          
}

Now i receive an empty HTML page with the text from the function, but i want to have the view active and just the function return the data to display it in the view.

My first try was to call a PHP-File in the dame directory of the view, but that didnt work either. If that would be possible it would be the best practice for me.

So maybe someone can give advice on how to get that work in a view.

Thanks a lot, stay healthy and safe.

0

Just an idea: I always try to find an example in Joomla itself. In Joomla 4 there is the spinner. Maybe the code with which this was inserted will help you:

https://github.com/joomla/joomla-cms/pull/25776

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.