Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript won't load when opening my webpage

Hello I am trying to run this code but every time I open my webpage it doesn't load and I don't get the text I echo with php in the file "money.php". But if I open the console in my browser and run the code it does load. Does anyone know how I could fix this?

<script type="text/javascript">
$('[data-update]').each(function() {
  var self = $(this);
  var target = self.data('update');   
  var refreshId =  setInterval(function() { self.load(target); }, self.data('refresh-interval'));
});
</script>
<div data-update="money.php" data-refresh-interval="500">
like image 525
Patric Nøis Avatar asked Jul 07 '15 10:07

Patric Nøis


People also ask

Why is my website not loading in the browser?

The website owner needs to renew the certificate before the expiry date. This keeps their website from getting flagged by browsers. When visiting the website, the browser compares this certificate against your system date. If your system date-time is outside the expiry period, the browser stops the page from loading.

Why is my JavaScript not working on my website?

You’re not giving very much information to go on, but the first thing to do is ensure that your JavaScript is actually loading, and that it is not executing before your document is completely loaded. The easiest way to do this is by including the script tag at the end of the body tag. Next, check the JavaScript console.

How to execute a script after the webpage has finished loading?

Method 1: Using onload method: The body of a webpage contains the actual content that is to be displayed. The onload event occurs whenever the element has finished loading. This can be used with the body element to execute a script after the webpage has completely loaded.

What to do when a website is not working on Windows?

1 Delete temporary files – Press Win+ R key together on your keyboard, type %temp% in “run” dialog box and hit OK, it will take you to the temporary files, ... 2 Delete history, cache, and cookies from browsers. 3 Reset your browsers to their default settings. ... 4 Check the Hosts file in Windows if a particular website is not working.


1 Answers

Use This

    <script type="text/javascript">
        $(function() {
            $('[data-update]').each(function () {
                var self = $(this);
                var target = self.data('update');
                var refreshId = setInterval(function () {
                    self.load(target);
                }, self.data('refresh-interval'));
            });
        });
    </script>

OR This

    <script type="text/javascript">
        $(document).ready(function() {
            $('[data-update]').each(function () {
                var self = $(this);
                var target = self.data('update');
                var refreshId = setInterval(function () {
                    self.load(target);
                }, self.data('refresh-interval'));
            });
        });
    </script>
like image 164
Abdulla Nilam Avatar answered Oct 15 '22 17:10

Abdulla Nilam