wp functions ajax get

Solutions on MaxInterview for wp functions ajax get by the best coders in the world

showing results for - "wp functions ajax get"
Carolina
22 May 2016
1function my_enqueue() {
2      wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/my-ajax-script.js', array('jquery') );
3      wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
4 }
5 add_action( 'wp_enqueue_scripts', 'my_enqueue' );
6
7//After localizing your JS file, you can use my_ajax_object object in your JS file:
8
9jQuery.ajax({
10    type: "post",
11    dataType: "json",
12    url: my_ajax_object.ajax_url,
13    data: formData,
14    success: function(msg){
15        console.log(msg);
16    }
17});