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.

1
  • 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 Commented Jan 24, 2013 at 6:06

3 Answers 3

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..

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

$(document).on("click","#delete_this_row<?php echo $poop?>", 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; });
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
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.