Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how-to-call-ajax-in-wordpress

function my_enqueue() {
      wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/my-ajax-script.js', array('jquery') );
      wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
 }
 add_action( 'wp_enqueue_scripts', 'my_enqueue' );

//After you can do in js
jQuery.ajax({
    type: "post",
    dataType: "json",
    url: my_ajax_object.ajax_url,
    data: formData,
    success: function(msg){
        console.log(msg);
    }
});
Comment

PREVIOUS NEXT
Code Example
Php :: linux delete php sessions 
Php :: laravel in array blade 
Php :: get the current date and time in php 
Php :: How to get a substring between two strings in PHP? 
Php :: laravel clear page cache 
Php :: how to get local current time in laravel 
Php :: laravel rule unique ignore 
Php :: How to validate a file type in laravel 
Php :: ::update() should not be called statically 
Php :: date formate in php 
Php :: get url link in php 
Php :: php for each schleife 
Php :: create migration, controller, model and seeder laravel 
Php :: pre function for PHP 
Php :: hmtl remove tag php 
Php :: php remove anchor tag from string 
Php :: mpdf output 
Php :: php strftime 
Php :: php sort array of array by key 
Php :: php sort array by value length 
Php :: Http request with bearer token Laravel 
Php :: get country from clouflare 
Php :: use model from variable laravel 
Php :: vscode open php tag autocomplete 
Php :: laravel 8 validation required if another field is not null 
Php :: order by in datatable laravel 
Php :: laravel username validation 
Php :: php absolute value 
Php :: static modal 
Php :: laravel 8 routes namespace 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =