Inserting AJAX/javascript values into custom WordPress table -


this voting functionality have on site. when user clicks button, vote inserted custom table in wordpress. ajax returns success message ok, nothing being inserted table. making mistake? here code(the ajax script , php code on 1 page)

    <script type="text/javascript" >         jquery(document).ready(function(){                 var counter;                 var id;            jquery('.fa-plus').one('click', function(){                 counter = 0;                 id = jquery(this).closest('div').prop("id");                 alert(id);                 //window.open("bride-profile.php");                 counter = counter+1;                 jquery('#votes-count').parent().html(counter);          });            jquery.ajax({             url    :"http://localhost/-wiz/wordpress/",             method :"post",             data   :{                         'action' : 'add_votes',                         'counter': counter,                         'id'     : id,             },             success:function(data){                 alert(data);                         }         }).error(function(){             alert("error!");     });    });     </script> <?php }//end of function my_action_javascript function add_votes(){         $id = $_post['id'];         $votes= $_post['counter'];         $wpdb->insert(             'fwwp_votes',             array(                 'bride_id' => $id,                 'votes'    => $votes             )         );     } add_action( 'wp_ajax_no_priv_add_votes', 'add_votes' ); add_action( 'wp_ajax_add_votes', 'add_votes' ); 

and bit of mark-up:

foreach($applications $application){             $id = $application->id;             echo                    '<div class="col-md-3" id="'.$id.'">',                     '<span class="pull-right votes" id="votes-count"><strong>0</strong></span>',                     '<div class="disp" id="disp"><i class="fa fa-heart fa-fw"></i> votes</div>',                     '<i class="fa fa-plus fa-fw"></i> vote '.$application ->user_name.',             '</div>';             } 

ok, turns out had insert jquery.ajax block onclick function, so:

jquery(document).ready(function(){                 jquery('.site-footer').hide();                 var counter;                 var id;         jquery('.fa-plus').one('click', function(){                 counter = 70;                 id      = jquery(this).closest('div').prop("id");                 alert(id);                 counter = counter+1;                 jquery('#votes-count').parent().html(counter);                   jquery.ajax({             url    : "http://localhost/-wiz/wordpress/vote",             type   : "post",             data   : {                         'action' : 'add_votes',                         'counter': counter,                         'id'     : id             },             success:function(response){                 console.log(response);              }         }).error(function(){             alert("error!");     });  

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -