WordPress.org

Ready to get started?Download WordPress

Forums

jQuery Ajax call (3 posts)

  1. Yaeko
    Member
    Posted 3 years ago #

    Hello,

    I'm making my first custom Ajax call in a single.php theme file.
    here's my js code:

    jQuery(document).ready(function(){
    
    		                        jQuery("#mp3file").live("click", function(){
        jQuery.ajax({
    	type: "POST",
    	url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
    	data: "action=update",
    	success: function(data){
            },
            complete: function(data){
    	     jQuery("#current_available_dl").html(data);
    	}
         });
        });
    });

    This is my code in the function.php file:

    function update_available_downloads(){
    
            global $post;
            $custom = get_post_custom($post->ID);
            $current = get_available_downloads($post->ID);
    
            $new_value = $current - 1;
    
            update_post_meta($post->ID, "current_amount_of_downloads", $new_value);
    
            return $new_value;
    
        }
    
        add_action('wp_ajax_update', 'update_available_download');
        add_action('wp_ajax_nopriv_update', 'update_available_download');

    Don't see what I'm doing wrong here?
    If anyone can help me out here?

    Thanks!

  2. Yaeko
    Member
    Posted 3 years ago #

    data: {action: 'update'}
    doesn't work either

  3. Yaeko
    Member
    Posted 3 years ago #

    Forgot the mention the problem :D

    The problem is that I don't get any feedback, no error, just the POST request in Firebug that "turns" red?

Topic Closed

This topic has been closed to new replies.

About this Topic