1

I have this situation with a device accessing a simple MySQL database using PHP. When I do a search, the results are written in an HTML file.

I have a second device (very basic android tablet) that has this HTML file opened. Using live.js it refreshes when it's contents change. What I need is this: a static message saying something like "Waiting for search results" and only when the contents of the page change the results are shown...

Something like this: On the tablet load 1.html (waiting for search results). When contents of page 2.html change (there was a search query), display that (2.html). After a push of a button (user input), let's go back to 1.html and wait for the contents of page 2.html to change again.

With live.js alone I can only watch for the file that's currently open...

Any idea on how I can achieve this? Thanks a bunch.

[EDIT - SOLVED] I got this to work like this: when the user of the tablet pushes a button it runs a PHP script that replaces the contents of the file (the previous search results) with the "waiting for results" text. Of course, it has live.js in the head, and when a new search occurs, the page reloads with the new search results.

It was easier than I thought I was overthinking it.

The PHP script:

<?php
ob_start();

$myFile = 'ana.html';
unlink($myFile);
$fh = fopen($myFile, 'w') or die ("can't open file");

$stringData = 
'<html>
  <head>
  <title>Rezultatele cautarii</title>
   <link rel="stylesheet" href="style.css">
   <script src="live.js"></script>
  </head>
  <body>
   <h1 class="button">Asteptam cererea</h1>
  </body>
 </html>';

fwrite($fh, $stringData);
fclose($fh);

header('Location: '.$myFile);

die();
?>
4

2 回答 2

0

你的意思是这样的吗?

document.write('<div id="loading"><br><br>Please wait...</div>');


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  document.getElementById("loading").style.display="none";
});
于 2013-05-21T07:42:39.323 回答
-1

我想你可以在 JavaScript 中运行 setInterval(),然后获取页面内容,就像它在之前的时间间隔一样,并使用校验和在 PHP 中进行比较?或者只是逐字比较。不过现在写代码太累了。

于 2013-05-21T07:56:34.803 回答