lundi 5 octobre 2015

Passing variable data from external jQuery file to options.php

I'm setting up a plugin that requires passing of a variable from a stand alone jQuery file to options.php. I have (I think) set up the scripts to be used in my plugin file like so:

function ndw_js_init(){
    wp_enqueue_script('jquery');
    wp_register_script( 'ndw_js', plugin_dir_url( __FILE__ ) . '/ndw_js.js', array( 'jquery' ), '', true );
    wp_enqueue_script( 'ndw_js', plugin_dir_url( __FILE__ ) . '/ndw_js.js', array(), '1.0.0', true);
    $scriptdata = array('admin_ajax' => admin_url( 'admin-ajax.php' ));
    wp_localize_script( 'ndw_js', 'toremove', $scriptdata);
}
add_action('admin_init', 'ndw_js_init');

Where I am coming unstuck is in the jQuery file. The variable is passed onclick. So far I have this which works fine (tested using an alert()):

$('tr td .widget-remove a').click(function(){
     var toremove = $(this).attr('rel');
     var url = 'options.php';
     // Out of ideas
});

So what I need is help to use the correct AJAX syntax to pass the value of var 'toremove' to 'options.php' and then do something in 'options.php' using the value of 'toremove'.

Hope that makes sense!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire