Hello.

This table is displayed in a loop.

<table> <tr> <td>текст 1</td> <td><iframe src="quare_05.php?id=1" class="if1"></iframe></td> </tr> <tr> <td>текст 2</td> <td><iframe src="quare_05.php?id=2" class="if1"></iframe></td> </tr> <tr> <td>текст 3</td> <td><iframe src="quare_05.php?id=3" class="if1"></iframe></td> </tr> <tr> <td>текст 4</td> <td><iframe src="quare_05.php?id=4" class="if1"></iframe></td> </tr> </table> 

There is a page in which inside the table, inside the cells, iframe is loaded. iframe identifies the id and makes a request to mysql via the re.php page, which changes the desired cell from 0 to 1 or 1 to 0, then jumps back to quare_05.php and displays a yes / no button. The point is that without JS I can make inquiries to the database without reloading the page.

 // вычисляем id $zapros = mysql_query("SELECT id,st FROM table ORDER BY id",$db); while($massiv = mysql_fetch_array($zapros)) { if($massiv["st"]==1) { echo "<form action=\"re.php\" method=\"post\"> <input type=\"hidden\" name=\"field0\" value=\"".$id."\"> <input type=\"hidden\" name=\"field1\" value=\"0\"> <input type=\"submit\" value=\"да\" class=\"blue\"> </form>"; } else { echo "<form action=\"re.php\" method=\"post\"> <input type=\"hidden\" name=\"field0\" value=\"".$id."\"> <input type=\"hidden\" name=\"field1\" value=\"1\"> <input type=\"submit\" value=\"нет\" class=\"oran\"> </form>"; } } 

Is it possible to implement the above without an iframe, but using JS?

  • 2
    Yes, you can - with the help of AJAX - zhenyab
  • great In this case, tell me with the code? - frank
  • Sorry, but no. But on the Internet you can find a lot of examples. - zhenyab
  • > great. In this case, tell me with the code? This is a job for the author! It is punished by closing the question and / or its removal. - Artem

2 answers 2

Connect the jQuery library. Then write this code:

 function load() { //просто какая-нибудь функция $.ajax({ url: "re.php", // файл, к которому обращается скрипт success: function (data) { $('.kakoyto_block').html(data); } //Здесь в блок с классом (или может быть ид) вставляется то, что ответил сервер, то есть получается загрузка контента без перезагрузки. }) } 

I think it’s understandable, just redo the code for yourself and you will be happy, this is of course govnokod, but I tried to convey the meaning and principle.

  • Thank you very much for this answer. Thanks to him, I began to understand jquery. - Freezze

Is it possible to implement the above without an iframe, but using JS?

Yes you can.