1 var ajaxurl = 'https://example.com/wp-admin/admin-ajax.php';
2 $.ajax({
3 url: ajaxurl,
4 type: 'post',
5 data: { action: 'register_user' ,"username": "arshia"},
6 success: function(response) { console.log(response); }
7 });
1<?php
2 // ajax call to this function
3 function register_user()
4 {
5 $username = $_POST['username'];
6 echo $username;
7
8 die();
9 }
10
11 add_action('wp_ajax_register_user', 'register_user');
12 add_action('wp_ajax_nopriv_register_user', 'register_user');
13
14?>