mercredi 29 juin 2016

Trying to capture value of a button and use ajax to submit a query

I have two buttons in a form. The update button updates the data and works fine. I am trying to implement a delete button that will delete the record based on which ever number is echoed in the button attribute value. Right now it is not doing anything.

<form id="update_form" action="" method="post">
<button id="update" type="submit" value="update">Update</button>   
<button id="unprocess" type="button" value="'.$order_no.'">DEL</button>  
</form>

My Jquery

$("#unprocess").click(function (e) {
         e.preventDefault();
         $.ajax({
             url: 'unprocess.php',
             data: $(this).val(value),
             type: 'POST',
             success: function (data) {
                 $(".error").css('display','none');
                 $(".success").css('display','block');
                 $('#search').focus();
             },
             error: function(data){
                 $(".success").css('display','none');
                 $(".error").css('display','block');
             }

         });

     });

My Query:

$order = $_POST['value'];
    $sql = "DELETE FROM table WHERE ord_no = $order";
    $query = odbc_exec($conn, $sql);

I made the changes on line data:$(this).val(value), now the browser is at least capturing the value of the button, but it is not being passed to the query. any ideas

Aucun commentaire:

Enregistrer un commentaire