3

I am using Magento 2.1.3 and I've made a block that contains a div with an id of "tableHolder", then I added this script to my themes html head:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>

<script>
jQuery(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        jQuery('#tableHolder').load('table.php', function(){
           setTimeout(refreshTable, 60000);
        });
    }
</script>

It is basically a table that needs to be refreshed every minute in my sidebar on every page.

Problem is that I'm getting jquery conflicts but the noconflict trick isn't working.

Then I thought maybe I could use the built in jquery and read that I need to do something with requireJS but I have yet to find useful information on actually using it. All of the guides give you the code you need to use but do not tell you where to use it.. for example: https://magecomp.com/blog/how-to-use-built-in-jquery-library-in-magento-2/

Does anybody have any suggestions? I have been trying to get this to work for days!

1

Okay I have it working using the code below in my themes head HTML but now there is like a white border around all web pages that have the table after it has loaded. If you go to my site, it will look right at first but when the prices table is loaded the page will have a white border around it. http://www.invest-in-bullion.com/

No idea why it is doing that, and there are no errors in the console..

Working Code:

<script type="text/javascript">
require(['jquery', 'jquery/ui'], function($){ 
     jQuery(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        jQuery('#tableHolder').load('table.php', function(){
           setTimeout(refreshTable, 60000);
        });
    }
 });
</script>

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.