The question is as follows. There is a simple code in which ajax updates the div. How to make it possible to update more than one block on the page?

Now the block with id = content handler temp.php is being updated. I would like to update the block with id = content-1, it will have its own handler temp-1.php

<html> <head> <title>HOME</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <link rel="stylesheet" type="text/css" href="style.css"> <script> function show() { $.ajax({ url: "temp.php", cache: false, success: function(html){ $("#content").html(html); } }); } $(document).ready(function(){ show(); setInterval('show()',100); }); </script> </head> <body> <div class="r"> <p class="r1">Температура дома</p> <div class="r2> <div class="r3" id="content"></div> <div class="r3"> C<sup>o</sup></div> </div> </div> <div class="r"> <p class="r1">Температура на балконе</p> <div class="r2> <div class="r3" id="content-1"></div> <div class="r3"> C<sup>o</sup></div> </div> </div> </body> </html> 

CODE TEMP.PHP

 <?php $myFile = "data.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo $theData; ?> 

  • Welcome to StackOverflow! You could add javascript and php tags to the question if you want it to get more attention. - naXa

1 answer 1

Add to function

 $.ajax({ url: "temp-1.php", cache: false, success: function(html){ $("#content-1").html(html); } }); 

Although I would have done better in one work and he returned Json. After that, you parse it and insert it into the necessary blocks.

  • Thank you very much! Sorry I can not plus you. Everything works))) The result can be seen here arduino.zhodinovel.com. - Ivan