Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter jonathanderouchie

    (@jonathanderouchie)

    so i found my solution, wp-blog-header is not needed.

    in my ajax i was calling the php page directly when i need to go through /wp-admin/admin-ajax.php. this is the most elegant solution because it will also take care of authorization.

    in jquery this looked like:


    function updateProduct(name, value) {
    jQuery.post(
    "/wp/wp-admin/admin-ajax.php", {
    action: "update_product",
    'cookie': encodeURIComponent(document.cookie),
    'name': value
    },function(msg) {
    jQuery('#debugger').append(msg+'
    ');
    });
    }

    then in my plugin top page i added an action


    add_action('wp_ajax_update_product', 'updateProduct' );

    and then the function to access the database as per the action:


    function updateProduct() {
    global $wpdb;
    $table_name = $wpdb->prefix . "ajax_test";
    $query = "INSERT INTO $table_name ($insert_key) VALUES ($insert_value)";
    }

    exit;
    }

Viewing 1 replies (of 1 total)