ajax call too functions php

Solutions on MaxInterview for ajax call too functions php by the best coders in the world

showing results for - "ajax call too functions php"
Laura
05 May 2020
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    });
Mae
18 Mar 2020
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?>