简体   繁体   中英

Mysql Delete row in form>table

Can you ajax post a single input from a form with a seperate form ajax function than the forms submit? I am trying to delete a table row within a form, without submitting the entire form.

particular Row hide from table... Display wise that row is removed..

$("#row"+i).animate({"height": "toggle"}, { duration: 1000 });

Next ajax function calls for deletion..

You need to access the row in jQuery and call remove on its object.

Live Demo

$('#rowId').remove();

You can use jQuery ajax to call php function with javascript, this post shows how to do it.

Yes you can send ajax post request via jquery.

Guidance code is as below.

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">

$(document).ready(function()
{

    $('.delete_link').click(function(e){

        e.preventDefault();
        var href = $(this).attr('href');
        var main_selector = $(this);


        $.ajax({

            url        : href,
            type       : 'post',
            dataType   : 'json',
            beforeSend : function()
            {
                //code before ajax send
            },
            success    : function(response)
            {
                if(response)
                {
                    main_selector.parent().remove();
                }
            }

        });

    });

});

</script>


<table>
    <tr>
        <td>Data1</td>
        <td><a href="delete.php?id=<?php echo $id ?>>" class="delete_link"></a></td>
    </tr>
    <tr>
        <td>Data2</td>
        <td><a href="delete.php?id=<?php echo $id ?>>" class="delete_link"></a></td>
    </tr>
    <tr>
        <td>Data3</td>
        <td><a href="delete.php?id=<?php echo $id ?>>" class="delete_link"></a></td>
    </tr>
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM