B
B
BoriHagen2020-04-24 21:57:33
PHP
BoriHagen, 2020-04-24 21:57:33

How to intercept html code in php?

There is a button, by clicking on which you need to intercept the block with all the content in which this button lies and insert another part of the document:

<?
for ($i=0; $i < count($stock_data[$i]); $i++) { 
      echo '<div class="main__categoties-wrapper__categorie-item hidden">
    <img class="item-img" width="100px" src="img/'.$stock_data[$i][1].'">
    <h1 class="main__categoties-wrapper__categorie-item__tittle">'.$stock_data[$i][2].'</h1>
    <h2>Артикул: '.$stock_data[$i][0].'</h2>
    <h2>Количество: '.$stock_data[$i][3].' шт.</h2>
    <form action="#" method="POST"><button class="add-item">Добавить</button></form>
    </div>';
  }
?>


Specifically here:
<form action="#" method="POST"><button class="add-item">Добавить</button></form>


I want to note that you need to intercept clean, already generated using php code, without php expressions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-04-24
@BoriHagen

The very basics. How PHP works.

P
ProF1NE, 2020-04-24
@ProF1NE

here jquery saves
for the button you write a click event handler, you take data from the parent block .parent()

$('.add-item').click(function() {
 var content = $(this).parent().html();
 $.ajax({ 
url: 'load.php',
 data: {"setting": value_setting},
 dataType: "html",
 success: function(date) {
 // // // функция того, что выходит при успешном завершении скрипта
});
}

and send it via ajax to php handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question