Hello, I need to do so that when you click on the button, the request is processed and does not go to another page. That is, as in the VC, for example, when you press a button.

html script:

<span style="display: none;" id="idGroups"><?php echo $hfs["idGroups"]; ?></span> <button name="delgroup" id="delgroup">Удалить</button> 

php script:

 <?php include("connectdb.php"); $id = $_POST["idgroup"]; if ($_POST['delgroup']!=null) { $delgroup = mysql_query("DELETE FROM groups WHERE id='$id'"); echo "Группа была успешна удалена. "; } else { echo "Ошибка. Группа не удалена!"; } ?> 
  • Um ... and what does AJAX and POST mean? Send a request by ajaxʻom (without form, by clicking on the keypad) - and you will be happy. - BOPOH
  • If you are writing this for users, not for yourself, then do not store the group id in the input type = "hidden" open source. id can be easily replaced and deleted by another group. - mountpoint
  • @mountpoint, it’s foolish to allow users to delete some group, so, rather, we are talking about some kind of admin panel. But even if we are talking about a simple user and a group (as, for example, a group of music in the VC), all the same, the removal code should be checked for the ability to delete this group by a specific user. So let him put what he wants, he will not succeed in messing things up anyway. This is better than messing up all sorts of hashes, etc., because in any case, even the hash can be faked and deleted something wrong. So, you should not complicate the task, it is enough to limit the verification of the rights to delete. - BOPOH
  • @BOPOH, yes, you are right. But still, the author will need to use at least some kind of protection, and not the code that is now - mountpoint

1 answer 1

  $(document).on('click', '.submit', function(){ var form = $(this).parents('form'); $.post(" путь к php файлу, обработчику формы", form.serialize(), function(){ // келлбек }); return false; }); 

Kellbekom make a conclusion result.

  • Sorry, but what is kellback and how to arrange it? - cnofss
  • @cnofss, meant "callback" ['kɔ: lbæk]. In this case, it is a callback function. This is nothing, I met those who read "Kalbak". )) - Deonis
  • @Deonis, I don’t understand at all how to do it. Can you at least leave an example? Yes, and you can do so that id had to be specified? I just have a lot of these forms, but, as I understand it, it is put to all forms. - cnofss
  • @cnofss, in general, @ ka5itoshka has already shown you almost everything. Instead of where the mysterious Kellback is written to him, you write a script that should be executed after the completion of the AJAX request. This function, among other things, accepts server response. Concerning id - did not understand. - Deonis
  • You can at least an example of a script, then what should I write in Kellbek, I just do not understand at all. At the expense of id, that is, so that the form had to be thrust into <div id = "form1"> </ div>. - cnofss