Aayush
Aayush

Reputation: 3

Post data ajax to php

I want to post the value when some click on delete. Please check the error

$.ajax({
         type: "POST",
         var checkid =  $('#delete').click(function(){ $(this).val();});,
         url: "survey-command.php",
         data: { checkid: checkid, }
            }).done(function( msg ) {
                alert( "Data Saved: " + msg );
       });  

I dont know how pass the value to this checkid variable

Upvotes: 0

Views: 49

Answers (3)

Manisha Patel
Manisha Patel

Reputation: 354

This the correct code that you need to use :

     $('#delete').click(function(){     
       $.ajax({
         type: "POST",
         url: "survey-command.php",
         data: { checkid: $(this).val();, }
            }).success(function( msg ) {
                alert( "Data Saved: " + msg );
        });
   }); 

Upvotes: 0

andrew
andrew

Reputation: 9583

Your code I believe should look like this:

$('#delete').click(function(){
   var checkid= $(this).val(); //assuming $('#delete') is an input.
                               // otherwise use $('#delete').html();
    $.ajax({
         type: "POST",
         url: "survey-command.php",
         data: { checkid: checkid, }
            }).done(function( msg ) {
                alert( "Data Saved: " + msg );
       }); 
 });

Upvotes: 1

cracker
cracker

Reputation: 4906

Use This

$('#delete').click(function(){ 
var checkid = $(this).val();
$.ajax({
         type: "POST",         
         url: "survey-command.php",
         data: { checkid: checkid, }
            }).done(function( msg ) {
                alert( "Data Saved: " + msg );
       });
});

Remove the Click from the $.ajax function as you need to fire the post event on the button click

Upvotes: 0

Related Questions