How to call ajax in wordpress

后端 未结 7 504
青春惊慌失措
青春惊慌失措 2020-11-28 10:49

My ajax call output is always showing 0 as output don\'t know why

In functions.php I have this code

function get_data() {
    $abc = \'         


        
7条回答
  •  渐次进展
    2020-11-28 11:18





    functions.php

    wp_enqueue_script('jquery');
    
    function addCustomer() {
    
        global $wpdb;
    
        $name = $_POST['name'];
        $phone = $_POST['phone'];
        $email = $_POST['email'];
        $address = $_POST['address'];
    
        if ( $wpdb->insert( 'customers', array(
            'name' => $name,
            'email' => $email,
            'address' => $address,
            'phone' => $phone
        ) ) === false ) {
            echo 'Error';
        } else {
            echo "Customer '".$name. "' successfully added, row ID is ".$wpdb->insert_id;
        }
        die();
    }
    add_action('wp_ajax_addCustomer', 'addCustomer');
    add_action('wp_ajax_nopriv_addCustomer', 'addCustomer');
    

    javascript

    
    

提交回复
热议问题