简体   繁体   中英

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

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 );
       }); 
 });

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

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 );
        });
   }); 

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