A
A
Alexey Vesnin2018-02-22 18:39:39
PHP
Alexey Vesnin, 2018-02-22 18:39:39

Why is the form not being submitted and $_POST is empty?

Hello everyone, I can't understand why the form is not submitted and $_POST is empty, help:

Here, JS:

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script>
        
        function ask() {
            var s = confirm("Вы уверены?");
            if(s) {
            document.forms['form'].submit();
              }
        }


        $(document).ready(function () {
            $("form").submit(function () {
                var formID = $(this).attr('id');
                var formNm = $('#' + formID);
                var message = $(formNm).find(".msgs"); 
                $.ajax({
                    type: "POST",
                    url: 'dashboard.php',
                    data: formNm.serialize(),
                    success: function (data) {
                        // Вывод сообщения об успешной отправке
                        message.html(data);
                    },
                    error: function (jqXHR, text, error) {
                        // Вывод сообщения об ошибке отправки
                        message.html(error);
                    }
                });
                return false;
            });
   
        });



    </script>


Here is the form:

<form id="delete_row" class="form" autocomplete="off"> 
            <?php foreach ($array as $row): ?>     
                <tr class="row_tr">
                    <td class="row_td"><?php echo $row['id'] ?></td>
                    <td class="row_td"><?php echo $row['referer_url'] ?></td>
                    <td class="row_td"><?php echo $row['utm_source'] ?></td>
                    <td class="row_td"><?php echo $row['utm_medium'] ?></td>
                    <td class="row_td"><?php echo $row['utm_campaign'] ?></td>
                    <td class="row_td"><?php echo $row['utm_term'] ?></td>
                    <td class="row_td"><?php echo $row['utm_content'] ?></td>
                    <td class="row_td"><?php echo $row['type'] ?></td>
                    <td class="row_td"><?php echo $row['source'] ?></td>
                    <td class="row_td"><?php echo $row['group'] ?></td>
                    <td class="row_td"><?php echo $row['utm'] ?></td>
                    <td class="row_td"><?php echo $row['ref'] ?></td>
                    <td class="row_td"><?php echo $row['cost'] ?></td>
                    <td class="row_td"><?php echo $row['date_inserted'] ?></td>
                    <input name="row_del_id" class="formInfo" type="hidden" value="<?php echo $row['id'] ?>">
                    <td class="row_td"><input type="submit" class="formBtn" name="delete_r" value="Удалить" onclick="ask(); return false;"></td>
                </tr>
            <?php endforeach; ?>
        </form>


What's wrong??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-02-22
@alexvdv

the callback on submit must have an event argument, call event.preventDefault() as the first line to suppress the form's default submit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question