Image Flickers when reloading on Ajax request. Can it be solved with Jquery?
I have a page that displays graph image which is refreshed every second via ajax call. The problem I am having is that image flickers every time it refreshes. I was told that I could solve it with jquery library but I am new to it and have no idea where to start. Can someone look at my code and let me know if this is a quick fix or point me in the right direction?
Here is my code
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en-US">
- <head profile="http://gmpg.org/xfn/11">
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Tire Change Report</title>
- <link rel="stylesheet" href="something.css" type="text/css" media="screen" />
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- var url = 'graph.php?random='+ Math.random();
- document.getElementById('graph').innerHTML = '<img src="' + url + '" />';
-
- var refreshId = setInterval(function() {
- document.getElementById('graph').innerHTML = '<img src="' + url + '" />';
- }, 1000);
- $.ajaxSetup({ cache: false });
- });
- </script>
- </head>
- <body>
- <div id="graph-title">
- <h1>Current Tire Change Report</h1>
- </div>
-
- <div id="graph"></div>
- </body>
- </html>