0

Following the tutorial listed here, I'm the data isn't being saved to the user meta I'm trying to set. The process itself seems simple enough, but the meta data isn't being saved. I don't get any console errors and the little success animation I have runs when I run the jQuery script.

<?php
    add_action( 'admin_footer', 'ring_jquery' );

    function ring_jquery() {
?>
<script type="text/javascript">
    jQuery('.ring-submit').on('click', function(){
        var u = jQuery(this).attr('user'),
            c = jQuery('.agt_ringc[user="'+u+'"]').val(),
            x = jQuery('.agt_ringx[user="'+u+'"]').val(),
            formData = 'ringu='+u+'&ringc='+c+'&ringx='+x;
        jQuery.ajax({
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            type: 'POST',
            data: formData,
            success: function(e){

                jQuery('.success[user="'+u+'"]').fadeIn(400).delay(400).fadeOut(400);

            },
            error: function(){

                jQuery('.fail[user="'+u+'"]').fadeIn(400).delay(400).fadeOut(400);

            }
        });
    });

</script>
<?php
} //End ring_jquery()

add_action('wp_ajax_my_action', 'ring_callback');

function ring_callback() {
    global $wpdb; // this is how you get access to the database

    $ringu = $_POST['ringu'];
    $ringc = $_POST['ringc'];
    $ringx = $_POST['ringx'];

    update_user_meta($ringu,'agt_ringc',$ringc);
    update_user_meta($ringu,'agt_ringx',$ringx);

    die(); // this is required to return a proper result
}
?>
1
add_action('wp_ajax_ring_callback', 'ring_callback');

Should be the hook you must be using to enable ring_callback function call.

  • Indeed! I figured this out a little later. I was also missing the action=ring_callback var setting in my data string. – Tim Plummer Nov 25 '13 at 14:45
  • I am glad you did :) But this is a common mistake i guess and this answer should be helpful to other community users. – sri Nov 25 '13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.