AJAX Call Via Vanilla JavaScript In WordPress Plugin Development

Thanks Muhammad,
Your solution is a fantastic working framework on which to base real world AJAX calls.
I just added this code to the plugin main php file for a shortcode so I could use it in the Front End too.

//For front end use in production
add_shortcode('wp_testingPlugin_shortcode', 'wp_testingPlugin_shortcode');
function wp_testingPlugin_shortcode() {
    wp_enqueue_script( 'ajax-script', plugin_dir_url( __FILE__ ).'my_javascript.js',  array('jquery') );
    wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
    return '<form id="searchForm">
        <input name="WhatToSearch" type="text" />
        <input type="submit" value="Search"/>
        <input type="reset" value="Reset"/>
        <div id="showReturnData"></div>
    </form>';
}

Leave a Comment

error code: 523