1

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.

Gvice
  • 393
  • 2
  • 10
  • I used $.post( 'delete_use.php', {number_use:"=$uses_row['number_use']?>"}, function( data ){ }); and it works well combined with my jquery below..... Thanks Everyone – Gvice Jan 24 '13 at 06:06

3 Answers3

1

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

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

Next ajax function calls for deletion..

Vaishu
  • 2,333
  • 3
  • 23
  • 25
0

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.

Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
  • $(document).on("click","#delete_this_row", function(){ var answer = confirm("Are you sure you would like to delete this use"); if(answer === true){ $(this).closest("table.appended_use").remove(); } else { } return false; }); – Gvice Jan 24 '13 at 04:57
  • that is my jquery and it works fine but i would like to send an ajax post to a php helper script to delete it from mysql – Gvice Jan 24 '13 at 04:58
0

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>
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90